Hi All,
Does anyone know a way in proc content or SQL to get a list of the "most recent variables created in the last data step"?
I have a big data set with large number of variables, and I'm interested to retrieve names of variables created in the last data step.
Thanks for help
That works. Add the LISTALL option to get the variables to list.
data class;
set sashelp.class ;
teen = age > 12;
run;
proc compare data=class(obs=0) compare=sashelp.class(obs=0) listall;
run;
That doesn't really make any sense. When you create a data set you create ALL of the variables for that data set. Even if some of them are coming from the inputs. The order of the variables will be determined by the order that the compiler notices the variables, not whether the step has made any modification to the values.
To see the most recently created data set you can use the &SYSLAST macro variable.
proc contents data=&syslast varnum ;
run;
Thanks for your response. Correct. I'm using SET statement on a dataset that has a large number of variables to create a new dataset with even larger number of variables created using a macro based on certain naming criteria I'm implementing. I was interested in retrieving the variable names that were created the last.
I was using the naive approach below but was wondering if there is a smarter way...!
data X;
set Y;
..... macro to create large number of variables;
run;
proc sql number;
select name , label
from dictionary.columns
where lowcase(Libname)='work' and lowcase(memname)='X'
and name not in
(select name from dictionary.columns
where lowcase(Libname)='work' and lowcase(memname)='Y');
quit;
I think your approach makes sense.
As the number of libraries/datasets gets bigs, the performance of disctionary.columns can get slow. If that happens, could be faster to just run PROC CONTENTS on both datasets to make OUT= datasets with the variable names, and then compare those.
I haven't tried it, but it's possible you could get PROC COMPARE to do the work for you. If you run:
PROC COMPARE base=x (obs=0) compare=y (obs=0);
run;
I wonder if it would still compare the metadata?
That works. Add the LISTALL option to get the variables to list.
data class;
set sashelp.class ;
teen = age > 12;
run;
proc compare data=class(obs=0) compare=sashelp.class(obs=0) listall;
run;
Thank you all for your responses!
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.