I use firstobs to create lag and merge it with existing data, but every time I have to rename all the columns as C1=_C1, C2=_C2 so that I can drop them easily since they are of no use to me.This is easy if the table has only 4-5 columns but I am working on datasets which have more than 50 columns.So I have to rename them all manually since I don't know how to use macros.
Is there a way through which I can create lag for a specific column of a table?
You are NOT(!!!) creating a lag, you create a look-ahead.
In the look-ahead table, use a keep= dataset option to keep only the column(s) needed:
data want;
merge
have
have (keep=c rename=(c=_c))
;
/* further processing */
run;
@Saurabh_Rana wrote:
No that was just a example I used to explain the question.
Then please post an excerpt of the data you have as usable data step, so that we don't have to guess what you have. And please show what you expect as result.
Here is . If you don't mind.
data have;
set sashelp.class;
run;
proc transpose data=have(obs=0) out=temp;
var _all_;
run;
proc sql noprint;
select cats(_name_,'=_',_name_) into :rename separated by ' ' from temp;
quit;
data want;
merge have have(firstobs=2 rename=(&rename));
run;
You are NOT(!!!) creating a lag, you create a look-ahead.
In the look-ahead table, use a keep= dataset option to keep only the column(s) needed:
data want;
merge
have
have (keep=c rename=(c=_c))
;
/* further processing */
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.