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

Good question, and I will explain the details, hoping maybe a better way to do things might come out of it!

 

I have 726 econometric variables - and I need to check their Time Series Stationarity. This check is done in a macro which produces very long reports-

making it hard to read if there are lots of variables - even 5 can be hard to read, since there are a lot of output stats.

Yes, I thought about having 10 variables in each groups, but I thought it would make it hard to read.

 

So, I thought I would try and produce smaller data-sets, with the variables just selected from adjacent groups of 5.

I've seen SAS code where you can say "Keep A1-A5" in the data-step and was hoping for something similar.

But the underlying original variable names (once your esolve varname1,varname2 etc.) are not similar at all.

 

So SAS complained again, but I'm now trying to refine Kurt's latest code - I think it works , just that it makes the last data-set empty (because I have 726 rather than 1000 names - not divisible by 5).

Reeza
Super User

Change the macro to take another parameter - a list of variables and add the KEEP to the data step to filter the data.

 

Then call the macro with your variable lists.

gamotte
Rhodochrosite | Level 12

Hello,

 

Here is an alternative program :

 

%macro breakup;

	%let n=1000;
	%let n1=5;
	%let nds=%eval(&n./&n1.);

	%if %eval(&nds.*&n1.) ne &n. %then %do;
		%let nds=&nds.+1;
	%end;

	proc sql noprint;
		SELECT NAME
		INTO :varlist SEPARATED BY " "
		FROM dictionary.columns
		WHERE LIBNAME="WORK" AND MEMNAME="HAVE";
	quit;

	data
		%do i=1 %to &nds.;
		have_&i ( keep=%scan(&varlist.,&n1.*(&i.-1)+1," ") -- %scan(&varlist.,%sysfunc(min(&n1.*&i.,&n.))," ") )
		%end;
		;
		set have;
	run;
%mend;

%breakup;

 

If the total number of variables is not a multiple of the number of variables per dataset, you'll have

to manually create the dataset for the remaining columns.

 

Edit I have edited the program to handle all cases.

nstdt
Quartz | Level 8

Thanks for the alternative solution! I plan to go through it as well and understand it.

 

I thought it was a simple task - break down a large dataset into smaller blocks of 5-6 variables each. But the implementation

turned out harder than I thought 🙂

Reeza
Super User

I would second going with @gamotte solution, with a small modification, the addition of an ORDER BY statement.

 

	proc sql noprint;
		SELECT NAME
		INTO :varlist SEPARATED BY " "
		FROM dictionary.columns
		WHERE LIBNAME="WORK" AND MEMNAME="HAVE"
Order by VARNUM; quit;
 

 

ballardw
Super User

@nstdt wrote:

Thanks for the alternative solution! I plan to go through it as well and understand it.

 

I thought it was a simple task - break down a large dataset into smaller blocks of 5-6 variables each. But the implementation

turned out harder than I thought 🙂


In one of the earlier posts you also have:

You're right, the resolved names of the macro-variables do not have any oredring pattern and I get errors.

 

If your variable names have some commonality of names such as cost1, cost2, cost3 ... costn, or price1, price2, price3

perhaps a portion of this could be use of variable lists such as Cost: to get all cost variables, or cost1-costn instead of generic &&var&num.

 

It might help to show how you build that list of variables.

Here's some examples putting ALL of the variable names into one macro variable but they have different orders:

proc sql noprint;
   select name into: vname separated by ' '
   from dictionary.columns
   where libname='SASHELP' and memname='CLASS'
   ;
quit;


proc sql noprint;
   select name into: vname2 separated by ' '
   from dictionary.columns
   where libname='SASHELP' and memname='CLASS'
   order by npos
   ;
quit;
proc sql noprint;
   select name into: vname3 separated by ' '
   from dictionary.columns
   where libname='SASHELP' and memname='CLASS'
   order by name
   ;
quit;

%put From first: &vname;
%put From second: &vname2;
%put From second: &vname3;

 

Perhaps that may have an effect.

Note that you might use one macro variable such as this and then use %scan to populate a list for each set.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 20 replies
  • 12019 views
  • 3 likes
  • 5 in conversation