BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
xxformat_com
Barite | Level 11

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 &notx. x:;
run;    

Would you have any other suggestion?

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

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;

View solution in original post

4 REPLIES 4
FreelanceReinh
Jade | Level 19

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;
xxformat_com
Barite | Level 11

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.

xxformat_com
Barite | Level 11

I like the two set statements.

Is there a specific reason for preferring a view over a dataset?

FreelanceReinh
Jade | Level 19

@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.

SAS Innovate 2025: Register Now

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!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 627 views
  • 1 like
  • 2 in conversation