BookmarkSubscribeRSS Feed
Ronein
Onyx | Level 15

Hello

I  have an input table that have one variable called YYMM (Type:char).

This table has only 3 rows with following data:  

1807

 1806

 1712

 

Task1- Create a new variable called NewVar  with following values (type: char):

1807  

1807+1806

1807+1806+1712

 

Thanks

Joe

 

Task2- Take the last value from NewVar column and create a sas macro varaible called vector

%put &vector will give is value    1807+1806+1712

 

Data inputTbl;
Input YYMM;
1807
1806
1712
;
Run;

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

Do like this

 

data inputTbl;
Input YYMM $;
datalines;
1807
1806
1712
;
Run;

data want;
   set inputTbl end=eof;
   length NewVar $100;
   NewVar=catx('+', NewVar, YYMM);
   retain NewVar;

   if eof then call symputx('vector', NewVar);
run;

%put &vector.;
Kurt_Bremser
Super User

Retain the new variable (set a sufficient length), use catx to concatenate the values, and call symput when you reach the end of the dataset (use end= option in the dataset).

 

Edit: what @PeterClemmensen said 😉

Astounding
PROC Star

Is this just for the sake of building skills?  Because you can skip the DATA step and go directly to creating the macro variable:

 

proc sql;

select MMYY into : vector separated by '+' from have;

quit;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1602 views
  • 1 like
  • 4 in conversation