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

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 800 views
  • 0 likes
  • 2 in conversation