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.

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!
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.

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