jeudi 13 août 2015

How to get the union of a different number of datasets? [SAS]

I'm running a code, almost in an automatic way. I just need to replace one value, and run. But there's one part where i have to do it 'by hand'.

It's the following code:

PROC SQL; CREATE TABLE DDATA.SUS_151_ALL AS 
 SELECT * FROM 
 (SELECT * FROM 
 DDATA.RFN_ID673 
 UNION
 SELECT * FROM 
 DDATA.RPFN_ID472 
 UNION
 SELECT * FROM 
 DDATA.RPFN_ID553);
 QUIT;

In this case, the clients i want to get the union are here:

 PROC SQL;
SELECT EN FROM DDATA.E5P_151; 
SELECT COUNT(*) FROM DDATA.E5P_151;
QUIT;

Here, i obtain the following results:

673
472
553 
---page break--
3

So, i want something that automatically would read the 3 datasets i wanted to get the union and create the table DDATA.SUS_151_ALL.

I have other clients where i have 8 id's to join, and having to do it by hand 100 times takes me some time. i would want just to replace the 151 , the source.

For example, for other client, let's say id=1000 like this one:

3
7
9
12
16
77
991
1028

I would want a program that would run this:

PROC SQL; CREATE TABLE DDATA.SUS_1000_ALL AS 
     SELECT * FROM 
     (SELECT * FROM 
     DDATA.RFN_ID3
     UNION
     SELECT * FROM 
     DDATA.RPFN_ID7 
     UNION
     SELECT * FROM 
     DDATA.RPFN_ID9
     UNION
     SELECT * FROM
     DDATA.RPFN_ID12
     UNION
     SELECT * FROM
     DDATA.RPFN_ID16
     UNION
     SELECT * FROM
     DDATA.RPFN_ID77
     UNION
     SELECT * FROM
     DDATA.RPFN_ID991
     UNION
     SELECT * FROM
     DDATA.RPFN_ID1028);
     QUIT;

Is this possible? Could you give me some hints?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire