BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
jenim514
Pyrite | Level 9

Hello,

Need output to retain the semicolon delimiter when the string is split up.  any ideas?

 

jenim514_0-1709929419021.png

Here is my code (col1-col3 renamed CMDECOD,1,2) after the transpose.

 
data tmp (drop= i word); set db.cm (keep=subject cmtrt_product recordid);
length nystr $200;
 
cmtrt_product = compbl(cmtrt_product);
do i = 1 to countw(cmtrt_product,';');
word = scan(cmtrt_product,i,';');
if length(nystr) + length(word) + 1 > 200 then do;
output;
nystr = word;
end;
else nystr = catx(';',nystr,scan(cmtrt_product,i,';'));
end;
if nystr ne '' then output;
run;
 
 
proc sort data=tmp; by subject recordid;
proc transpose data=tmp out=want (drop=_name_); 
by subject recordid ;
var nystr;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

If you need a semicolon the add one before writing.

Instead of

if nystr ne '' then output;
run;

try

if nystr ne '' then do;
    nystr = cats(nystr,';');
    output;
end;
run;

View solution in original post

2 REPLIES 2
ballardw
Super User

If you need a semicolon the add one before writing.

Instead of

if nystr ne '' then output;
run;

try

if nystr ne '' then do;
    nystr = cats(nystr,';');
    output;
end;
run;
himself
Pyrite | Level 9

Hi, I came across such a question answerd in sas community:

 

Kindly have a look and see if you can incorporate the same in you code:

 

link one split variables 

Link two split variables 2 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 718 views
  • 0 likes
  • 3 in conversation