BookmarkSubscribeRSS Feed
littlestone
Fluorite | Level 6
hello all, the following is my code:



data test;
input (var1-var8) ($);
cards;
a a b b c c d d
;
run;

Data test2;
set test;
array intermediate[8] $ var1-var8;
array newvar(4) $;
do i=1 to 4;
newvar(i)= intermediate[2*i-1]||"/"||intermediate[2*i];
end;
keep newvar1-newvar4;
run;



I am expecting dataset test2 will be:
a/a b/b c/c d/d

however, the actual result is:
a b c d

what mistake have I made?
2 REPLIES 2
RickM
Fluorite | Level 6
First off, || doesn't remove blanks and the new variables are not long enough to store the entire new string. The catx function might be a better way to go.

data test;
input (var1-var8) ($);
cards;
a a b b c c d d
;
run;

Data test2;
set test;
length newvar1-newvar4 $20;
array intermediate[8] $ var1-var8;
array newvar(4) $;
array newvarA(4) $;
do i=1 to 4;
newvar(i)= intermediate[2*i-1]||"/"||intermediate[2*i];
newvarA(i)=catx("/",intermediate[2*i-1],intermediate[2*i]);
end;
keep newvar1-newvar4 newvarA1-newvarA4;
run;
littlestone
Fluorite | Level 6
Thank you very much.
What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 2 replies
  • 1445 views
  • 0 likes
  • 2 in conversation