As far as I know it is not possible to use "not" with <varname>: to list a series of variable not starting with.
In other words, it is not possible to do this:
data tmp;
x1=1;
x2=2;
y1=1;
y2=2;
run;
proc print data=tmp;
var not(x:) x:;
run;
We can still use a macro variable:
data tmp;
x1=1;
x2=2;
y1=1;
y2=2;
run;
proc sql noprint;
select name into: notx separated by ' '
from dictionary.columns
where libname='WORK' and
memname='TMP' and
upcase(name) not like 'X%';
quit;
proc print data=tmp;
var ¬x. x:;
run;
Would you have any other suggestion?
Hi @xxformat_com,
In your particular example you could use
proc print data=tmp;
var y: x:;
run;
or
proc print data=tmp;
id y:;
run;
Other forms of variable lists might be applicable to different cases.
The DROP= dataset option can exclude variable lists:
proc print data=have(drop=x:);
run;
In your example it could be used in a DATA step view:
data v / view=v;
set tmp(drop=x:);
set tmp;
proc print;
run;
Hi @xxformat_com,
In your particular example you could use
proc print data=tmp;
var y: x:;
run;
or
proc print data=tmp;
id y:;
run;
Other forms of variable lists might be applicable to different cases.
The DROP= dataset option can exclude variable lists:
proc print data=have(drop=x:);
run;
In your example it could be used in a DATA step view:
data v / view=v;
set tmp(drop=x:);
set tmp;
proc print;
run;
I agree about y: but it is just a demo example. But the question was about listing all the variables which are not starting with x as in real life, we either don't know the name of the variables in advance or the list is so long that automating is worth it.
I like the two set statements.
Is there a specific reason for preferring a view over a dataset?
@xxformat_com wrote:
I like the two set statements.
Is there a specific reason for preferring a view over a dataset?
I thought using a view is conceptually closer to your intention of just printing an existing dataset as opposed to creating a new one with selected or reordered variables.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.