DATA Step, Macro, Functions and more

How to store column values as macro variable?

Accepted Solution Solved
Reply
Contributor
Posts: 71
Accepted Solution

How to store column values as macro variable?

Hello,

I want to take the value of a entire single column and store it as a macro variable. I tried using :into clause and it is giving me just the first row value but if i use separated by ',' it works fine. The problem with that is  I don't want the macro variable with commas.

Data col1;

input serial_no $3.;

cards;

100

120

130

140

;

Run;

Proc Sql noprint;

Select serial_no into :sno

from col1

;

Quit;

%Put %sno;

The above gives me an output of 100 but i want it as 100 110 650 435(no commas in between).

Thanks in advance for your help!


Accepted Solutions
Solution
‎10-02-2012 09:30 PM
Respected Advisor
Posts: 3,124

Re: How to store column values as macro variable?

Hi, you can separate by any delimiter of your choice, in this case you want blank.

Proc Sql noprint;

Select serial_no into :sno separated by ' '

from col1

;

Quit;

%Put &sno;

Haikuo

View solution in original post


All Replies
Solution
‎10-02-2012 09:30 PM
Respected Advisor
Posts: 3,124

Re: How to store column values as macro variable?

Hi, you can separate by any delimiter of your choice, in this case you want blank.

Proc Sql noprint;

Select serial_no into :sno separated by ' '

from col1

;

Quit;

%Put &sno;

Haikuo

Contributor
Posts: 71

Re: How to store column values as macro variable?

Ah.. simple changeSmiley Happy. Thank you very much!!

Occasional Contributor
Posts: 5

Re: How to store column values as macro variable?

Good...  I used to do it with a data step, using retain, call symput, catx(..)..This one looks neat.

Occasional Contributor
Posts: 8

Re: How to store column values as macro variable?

Hello,

 

how to store column values with strings as macro variable?

 

Ex:

data dts;

           length l_dset $15 ttl $100;

           infile datalines delimiter='|';

           input l_dset $ ttl $;

                   datalines;

LIS002|Illegible text

LIS003|Duplicate AEs

LIS004|Overlapping AEs

LIS005|Duplicate Conmeds

LIS015|Abacavir HSR and AE consistency

LIS021|Compare age at screening

LIS023|Laboratory date sample not in Chronolical order

LIS024|Laboratory sample time is not the same for other samples collected at same visit

LIS025|Multiple visit date

LIS026|Multiple sample date

LIS027|Duplicate Samples on same sample date

LIS028|LowerCase Units

;

run;

 

I want only the ttl column from the dataset dts to be stored in macro variable and fetch those for later use.

 

Please help me on this. i have been struggling with this.

 

thanks,

Pavan.Ch

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 2140 views
  • 1 like
  • 4 in conversation