BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Altal
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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;

View solution in original post

5 REPLIES 5
Tom
Super User Tom
Super User

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;

Altal
Calcite | Level 5

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;

Quentin
Super User

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?

The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.
Tom
Super User Tom
Super User

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;

Altal
Calcite | Level 5

Thank you all for your responses!

SAS Innovate 2025: Register Now

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!

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1069 views
  • 3 likes
  • 3 in conversation