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
Ammonite | Level 13

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
Ammonite | Level 13

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