If I create one variable list like this,
%let varlist=c1-c9;
How to get the number of variables in &varlist?
If I %let n=%sysfunc(countw(&varlist)), &n will be 2.
Any way to get the exact number of variables in &varlist?
Thanks!
Second way :
%let varlist=c1-c9;
data _null_;
array a{*} &varlist;
call symputx('n',dim(a));
stop;
run;
%put &n ;
Ksharp
How about :
%let varlist=c1-c9;
%let start=%scan(&varlist,1, ,kd);
%let end=%scan(&varlist,-1, ,kd);
%let n=%eval(&end-&start+1) ;
%put &n ;
Ksharp
Second way :
%let varlist=c1-c9;
data _null_;
array a{*} &varlist;
call symputx('n',dim(a));
stop;
run;
%put &n ;
Ksharp
Thank you, Ksharp!
Another question.
%let varlist=c1-c4 d1 d9;
How can I get the variable name list like c1 c2 c3 c4 d1 d9?
Thanks!
proc transpose data=have(obs=0) out=varlist;
var c1 c2 ..... ; * any list of variables that exist in have;
run;
You get a SAS data set and you can use it to answer all kinds of questions including how many.
Acutally NULL has already given you a good solution.
%let varlist=c1-c4 d1 d9;
data _null_;
length list $ 200;
array a{*} &varlist;
do i=1 to dim(a);
list=catx(' ',list,vname(a{i}));
end;
call symputx('list',list);
stop;
run;
%put &list ;
Ksharp
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.