DATA REVENUE;
MERGE REV_1004 (KEEP = ID REVENUE RENAME =(REVENUE = REV1004)
REV_1005 (KEEP = ID REVENUE RENAME =(REVENUE = REV1005)
REV_1006 (KEEP = ID REVENUE RENAME =(REVENUE = REV1006)
REV_1007 (KEEP = ID REVENUE RENAME =(REVENUE = REV1007)
REV_1008 (KEEP = ID REVENUE RENAME =(REVENUE = REV1008)
REV_1009 (KEEP = ID REVENUE RENAME =(REVENUE = REV1009)
REV_1010 (KEEP = ID REVENUE RENAME =(REVENUE = REV1010)
REV_1011 (KEEP = ID REVENUE RENAME =(REVENUE = REV1011)
REV_1012 (KEEP = ID REVENUE RENAME =(REVENUE = REV1012)
REV_1101 (KEEP = ID REVENUE RENAME =(REVENUE = REV1101)
REV_1102 (KEEP = ID REVENUE RENAME =(REVENUE = REV1102)
REV_1103 (KEEP = ID REVENUE RENAME =(REVENUE = REV1103);
BY ID;
RUN;
I would like to write the same code in SQL and output supposed to be same, any help?
I am exploring SQL options, thus trying to convert SAS data steps and procedures in to PROC SQL.
by the way do we have FILM JOIN? never heard of it. how to use?
I would echo suggestion from above, union or stack datasets and then transpose from wide to long.
The only thing that I would do with this code is that I would automate it so I only need to set begin and end months, and the code is built dynamically.
%let begin='01apr2010'd;
%let end='01mar2011'd;
data _null_;
length command $100;
date = &begin;
call execute('data revenue; merge ');
do while (date <= &end);
yymm = substr(put(year(date),z4.),3,2)!!put(month(date),z2.);
command = 'rev_'!!yymm!!' (keep=id revenue rename=(revenue = rev'!!yymm!!')';
call execute(command);
date = intnx('month',date,1,'begin');
end;
call execute('; by id; run;');
run;
In this particular case one could also shorten the code to:
DATA _NULL_;
SET sashelp.vtable end=last;
where libname eq 'WORK' and substr(memname,1,4) eq 'REV_';
if _N_ eq 1 then call execute('DATA REVENUE; MERGE ');
call execute(strip(memname)||' (KEEP = ID REVENUE RENAME =(REVENUE = '||strip(compress(memname,"_"))||'))');
if last then call execute(';BY ID; RUN;');
RUN;
- Cheers -
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.