BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
unnati
Obsidian | Level 7
  1. Given dataset one with Var; How do you get New var in the dataset?

                       Var                   New Var

                                A                         A

                               B                        AB

                                C                       ABC

                                D                     ABCD

can anyone explain how to get this answer with using retain statement or other option

 

Thank you

Unnati 

1 ACCEPTED SOLUTION

Accepted Solutions
SASJedi
SAS Super FREQ

HOw about something like this?

data have;
   input Var:$1;
datalines;
A
B
C
D
;
data want;
   set have;
   length NewVar $4;
   retain NewVar;
   NewVar=CATS(NewVar,Var);
run;
Check out my Jedi SAS Tricks for SAS Users

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20
data have;
do _n_=65 to 68;
var=byte(_n_);
output;
end;
run;

data want;
set have;
length want $10;
retain want;
want=cats(want,var);
run;

 Hi @unnati  it;s plain vertical concatenation. Just a matter of time before you get the understanding. HTH

SASJedi
SAS Super FREQ

HOw about something like this?

data have;
   input Var:$1;
datalines;
A
B
C
D
;
data want;
   set have;
   length NewVar $4;
   retain NewVar;
   NewVar=CATS(NewVar,Var);
run;
Check out my Jedi SAS Tricks for SAS Users

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 595 views
  • 1 like
  • 3 in conversation