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 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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