BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
My_SAS
Calcite | Level 5

Hi i am having data like this

data Temp;
input name $ 1-30;
cards;
cell,van,zim
zim,app,Run
Mor,App,hen
zac,zil,run,fun,app,box,cat

run;

But i want the output in the sort order i dont know how many obs with comma will come

output

cell,van,zim
app,run,zim
app,hen,mor
app,box,cat,fun,run,zac,zil

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

OK. Let me try it.

data Temp;
input name $ 1-30;
cards;
cell,van,zim
zim,app,Run
Mor,App,hen
zac,zil,run,fun,app,box,cat
zac,bil
;
run;
proc sql noprint;
select max(count(name,','))+1 into : max from temp;
quit;

data want;
 set temp;
 array _a{&max} $ ;
 do i=1 to &max;
  _a{i}=lowcase(scan(name,i,','));
 end;
 call sortc(of _a{*});
 name=catx(',',of _a{*});
 drop i _a:;
run;


Ksharp

View solution in original post

4 REPLIES 4
Ksharp
Super User

OK. Let me try it.

data Temp;
input name $ 1-30;
cards;
cell,van,zim
zim,app,Run
Mor,App,hen
zac,zil,run,fun,app,box,cat
zac,bil
;
run;
proc sql noprint;
select max(count(name,','))+1 into : max from temp;
quit;

data want;
 set temp;
 array _a{&max} $ ;
 do i=1 to &max;
  _a{i}=lowcase(scan(name,i,','));
 end;
 call sortc(of _a{*});
 name=catx(',',of _a{*});
 drop i _a:;
run;


Ksharp

sas_Forum
Calcite | Level 5

Hi khsarp some times i will run my job with 0 records when i do this i am getting Error what can i do

as we run in DI and we run this job daily some times we get o kb file then also we run the job then job fails

what can i do for this.

data Temp;

input name $ 1-30;

cards;

;

run;

proc sql noprint;

select max(count(name,','))+1 into : max from temp;

quit;

data want;

set temp;

array _a{&max} $ ;

do i=1 to &max;

  _a{i}=lowcase(scan(name,i,','));

end;

call sortc(of _a{*});

name=catx(',',of _a{*});

drop i _a:;

run;

Ksharp
Super User
data Temp;
input name $ 1-30;
cards;
;
run;



%macro sort_char;
%let dsid=%sysfunc(open(temp));
%let nobs=%sysfunc(attrn(&dsid,nobs));
%let dsid=%sysfunc(close(&dsid));
%put &nobs ;
%if &nobs=0 %then %return;
proc sql noprint;
select max(count(name,','))+1 into : max from temp;
quit;

data want;
 set temp;
 array _a{&max} $ ;
 do i=1 to &max;
  _a{i}=lowcase(scan(name,i,','));
 end;
 call sortc(of _a{*});
 name=catx(',',of _a{*});
 drop i _a:;
run;
%mend sort_char;

%sort_char






Ksharp

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
  • 4 replies
  • 863 views
  • 0 likes
  • 3 in conversation