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
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
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
Thqs Ksharp
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;
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
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.