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

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!

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
  • 2723 views
  • 2 likes
  • 3 in conversation