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

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

Second way :

%let varlist=c1-c9;

data _null_;
array a{*} &varlist;
call symputx('n',dim(a));
stop;
run;
%put &n ;

Ksharp

View solution in original post

6 REPLIES 6
Ksharp
Super User

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

Ksharp
Super User

Second way :

%let varlist=c1-c9;

data _null_;
array a{*} &varlist;
call symputx('n',dim(a));
stop;
run;
%put &n ;

Ksharp

MikeTurner
Calcite | Level 5

Thank you, Ksharp!

MikeTurner
Calcite | Level 5

Another question.

%let varlist=c1-c4 d1 d9;

How can I  get the variable name list like c1 c2 c3 c4 d1 d9?

Thanks!

data_null__
Jade | Level 19

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.

Ksharp
Super User

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

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
  • 6 replies
  • 1133 views
  • 7 likes
  • 3 in conversation