2

I have one SAS dataset that has a column with values that I want to use as a macro variable. Say the SAS dataset looks like this with one column:

varname
34
367
399
87

What I want is for all of the values in the column to become a concatenated string in a macro variable (suitable for using in an if statement with the in operator). The result would be equivalent to this:

%let var = %str('34','367','399','87');

How would I accomplish this?

1 Answer 1

5

I would use PROC SQL, but there are other ways:

proc sql noprint;
select "'" || varname || "'"
   into :var separated by ','
   from have;
quit;

%put var: &var;

This will concatenate the variable values with a ' on either side. The separated by piece will put a , between all the values. :var tells SQL to save the results in a macro named var;

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.