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.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

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