BookmarkSubscribeRSS Feed
George_S
Fluorite | Level 6

data one;

input a b c a_123 b_123 x_123 y_123  z_123;

run;

data two;

set one;

keep a_123 b_123 x_123 y_123  z_123;

run;

My question is if there are too much variables end with '_123'(I can't list all of them here),how to keep these variables in an easy way?

I know ':' operator can keep variables start with special characters but not end with.

Thanks!

3 REPLIES 3
Linlin
Lapis Lazuli | Level 10

How about:

(note: libname and memname must be capital letters)

proc sql noprint;

   select name into : names separated by ' '

   from dictionary.columns

   where libname='WORK' and memname='HAVE' and upcase(name) like '%_123' ;

quit;

data want;

  set have(keep=&names);

run;

Linlin

kuridisanjeev
Quartz | Level 8

Just curious....

How to do this  in Data Step???

Haikuo
Onyx | Level 15

You could have more than one data step approaches. For one, you could use meta view for data step, such as sashelp.vcolumn, and use a combination of substr() and length to obtain the variable names. For two, you could use array vname to grab the variable names that meets criteria.

You could also use proc contents instead of SQL to get the variables names.

However, in case, by supporting operators such as 'like', 'contains', SQL is more native to the job.

Haikuo

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 3 replies
  • 8516 views
  • 3 likes
  • 4 in conversation