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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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