Help using Base SAS procedures

how to look at a bunch variables with only on digit diff inbeded in name

Reply
Occasional Contributor
Posts: 18

how to look at a bunch variables with only on digit diff inbeded in name

data structure:
var1same var2same var3same------var100same

I donot want to list them all one by one when I look at them like following.
proc means;
var var1same var2same var3same------var100same;
run;

Is there a short cut way to list these similar variables without typing them all?

Thanks.
Respected Advisor
Posts: 3,899

Re: how to look at a bunch variables with only on digit diff inbeded in name

Hi Jenn

Just read Olivier's answer to your last question:
"You can use this shortcut : VAR var2: ; which stands for 'all variables having their name beginning with "VAR2" '

So why don't you just write "VAR var:" ?

Below my more complicated approach before Olivier reminded me how to do things.

You can also use a syntax like "VAR x -- c". This gives you all the variables like they are stored in the table (NOT alphabetically: it's COLNUM! This returns all the vars between Colnum of X to Colnum of C).

HTH
Patrick

data have;
a=1;
c=2;
var1same=97;
b=3;
d1=4;
var3same=98;
d2=5;
d10=6;
var2same=99;
d5=7;
output;
run;

%let VarList=;
proc sql;
select name into :VarList separated by ' '
from dictionary.columns
where libname='WORK' and memname='HAVE' and upcase(name) like upcase('var%same')
order by name;
%put &VarList;
quit;

proc means;
var &VarList;
run;

Message was edited by: Patrick
Occasional Contributor
Posts: 18

Re: how to look at a bunch variables with only on digit diff inbeded in name

Hi, Patrick:

Thanks for your reply.

By the way, the reason I could not use the olivier's short cut is that if I use var:, it will read more than necessary. There are hundreds of variable started with var.
Ask a Question
Discussion stats
  • 2 replies
  • 92 views
  • 0 likes
  • 2 in conversation