BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
forumsguy
Fluorite | Level 6

Hi All,

Following is my dataset

data have;

input var1 $20;

cards;

robert

is

my

boss

;

run;

Now , i want to have one single macro variable which would resolve to robert is my boss

In short, I want to concatenate all obseervations in one single macro. Catch is not to use Proc sql. I know below single statement would have solved my purpose, but I have to use datastep and not proc sql.

proc sql; select var1 into :macvar1 separated by " " from have;


Any help would be highly appreciated

1 ACCEPTED SOLUTION

Accepted Solutions
Keith
Obsidian | Level 7

I had the same idea as .  Here is the code I wrote

data _null_;

set have end=last;

length result $200;

retain result;

call catx(" ",result,var1);

if last then call symput('macvar1',result);

run;

%put &macvar1.;

View solution in original post

4 REPLIES 4
LinusH
Tourmaline | Level 20

Why not SQL?

One should chose whatever tool seems best/easiest for each task...

Anyway, concatenate your vaues into a retained value, and the call symput when the data step reaches the last record/EOF (I guess that your real life data is not provided in datalines)

Data never sleeps
forumsguy
Fluorite | Level 6

Agree Linus, but that's what my client's requirement is. They are insisting on data steps as they previously had experienced that having mixed macro variables (few from datastep and few from proc sql) tend to create problems in their environment. Anyways, can you please elaborate on your approach (EOF and retain). I tried using that as well , however it could not work.

Keith
Obsidian | Level 7

I had the same idea as .  Here is the code I wrote

data _null_;

set have end=last;

length result $200;

retain result;

call catx(" ",result,var1);

if last then call symput('macvar1',result);

run;

%put &macvar1.;

forumsguy
Fluorite | Level 6

Thanks keith... that worked .. I had used retain earlier in sum but never thought it could be applied to char variables as well

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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