Help using Base SAS procedures

List of Most Recent Created Variables

Accepted Solution Solved
Reply
Contributor
Posts: 62
Accepted Solution

List of Most Recent Created Variables

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


Accepted Solutions
Solution
‎03-03-2014 09:11 AM
Super User
Super User
Posts: 6,499

Re: List of Most Recent Created Variables

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


All Replies
Super User
Super User
Posts: 6,499

Re: List of Most Recent Created Variables

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;

Contributor
Posts: 62

Re: List of Most Recent Created Variables

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;

PROC Star
Posts: 1,231

Re: List of Most Recent Created Variables

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?

Solution
‎03-03-2014 09:11 AM
Super User
Super User
Posts: 6,499

Re: List of Most Recent Created Variables

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;

Contributor
Posts: 62

Re: List of Most Recent Created Variables

Thank you all for your responses!

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

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