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?

BASUG is hosting free webinars Next up: Jane Eslinger presenting PROC REPORT and the ODS EXCEL destination on Mar 27 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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