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 (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at 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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 991 views
  • 3 likes
  • 3 in conversation