BookmarkSubscribeRSS Feed
sas_
Fluorite | Level 6
data a;
input id s $ 3-118;
datalines;
1 prg-code,main,IT-Hardware,Ins,Main,Non_IT- ,WOrk-Hardwrk,giveup,main,doit, -Nowork,ceo-cash,main,user,repair,nonit,
run;

LOGIC :I WANT TO MOVE IT IN TO ANOHTER ROW BASED ON "- "(HI FUN) BEFORE HIFUN FIRST COMMA .

i wnat it in data set a2 as

output:

1 prg-code,main
1 IT-Hardware,Ins,Main
1 Non_IT-
1 WOrk-Hardwrk,giveup,main,doit
1 -Nowork
1 ceo-cash,main,user,repair,nonit
1 REPLY 1
art297
Opal | Level 21
Presuming hi fun represents hyphen, the following might serve the purpose. There is probably a more direct way with regular expressions, but I am still just learning those:
[pre]
data a;
informat s $200.;
input id s &;
datalines;
1 prg-code,main,IT-Hardware,Ins,Main,Non_IT- ,WOrk-Hardwrk,giveup,main,doit, -Nowork,ceo-cash,main,user,repair,nonit,
;
run;

data a2 (keep=id want);
set a;
length want $35;
array x (99) $35.;
i=1;
do while (scan(s,i,',') ne "");
x(i)=scan(s,i,',');
i+1;
end;
want="";
do j=1 to i;
want=catx(',',want,x(j));
if j eq i or index(x(j+1),"-") gt 0 then do;
output;
want="";
end;
end;
run;
[/pre]
HTH,
Art
---------
> data a;
> input id s $ 3-118;
> datalines;
> 1 prg-code,main,IT-Hardware,Ins,Main,Non_IT-
> ,WOrk-Hardwrk,giveup,main,doit,
> -Nowork,ceo-cash,main,user,repair,nonit,
> run;
>
> LOGIC :I WANT TO MOVE IT IN TO ANOHTER ROW BASED ON
> "- "(HI FUN) BEFORE HIFUN FIRST COMMA .
>
> i wnat it in data set a2 as
>
> output:
>
> 1 prg-code,main
> 1 IT-Hardware,Ins,Main
> 1 Non_IT-
> 1 WOrk-Hardwrk,giveup,main,doit
> 1 -Nowork
> 1 ceo-cash,main,user,repair,nonit

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 1 reply
  • 702 views
  • 0 likes
  • 2 in conversation