SAS Programming

DATA Step, Macro, Functions and more
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-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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
  • 1079 views
  • 1 like
  • 2 in conversation