Help using Base SAS procedures

How to edit text before running it as code

Reply
N/A
Posts: 0

How to edit text before running it as code

Hi,

I have a list of over 2,000 variables.

To run a query on them I need to use the following code:

where variable in ('xxx1', 'xxx2', 'xxx3',....etc)

The variables are currently in the format of: xxx1 xxx2 xxx3

Is there a short cut to format the variables so i do not have to manually add ' ' , (the neccessary punctuation) to each of the variables?

Any help most appreciated!
Super Contributor
Super Contributor
Posts: 3,174

Re: How to edit text before running it as code

From the SAS support website and its incredible resource of code snippets and examples -- which I found using a GOOGLE.COM advanced search with site:sas.com to limit the search:

Sample 25976: Create a macro variable that contains a quoted list
http://support.sas.com/kb/25/976.html


Scott Barry
SBBWorks, Inc.
N/A
Posts: 0

Re: How to edit text before running it as code

Thanks so much for that Scott!

That code was very helpful.

Is it possible to keep the newly punctuated variables just as a data set?

i.e. I do not need the following:

data master;
input empl $ job $;
datalines;
12345 clerk
34567 rep
00001 analyst
;

proc print data=master;
where empl in(&list);
run;
Super Contributor
Super Contributor
Posts: 3,174

Re: How to edit text before running it as code

Use PROC SQL to generate the macro variable, as demonstrated. Then code a DATA step with a RETAIN statement, specifying your desired SAS data variable name, and initialize the variable with the "generated" SAS macro variable, specified in double-quotes (not single-quotes -- otherwise the macro var is not going to be resolved).

Scott Barry
SBBWorks, Inc.
N/A
Posts: 0

Re: How to edit text before running it as code

I ended up concatenating the data in excel because it was the code I needed to format & not the output.

Thanks for your help.
Ask a Question
Discussion stats
  • 4 replies
  • 100 views
  • 0 likes
  • 2 in conversation