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
Quartz | Level 8

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

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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