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 -
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.