Like this?
data HAVE;
input VAR1 $ VAR2 $ VAR3 $;
cards;
1 3 C
4 -5 B
7 . .
9 -10 .
12 . N
run;
data WANT;
set HAVE;
length V1-V3 $8;
V1=VAR1; output;
if VAR3 ne ' ' then do;
V3=VAR3;
output;
end;
V3=' ';
if VAR2 ne ' ' then do;
V1=compress(VAR2,'-');
output;
if VAR3 ne ' ' then do;
V3=VAR3;
output;
end;
end;
drop VAR1-VAR3;
rename V1=VAR1 V2=VAR2 V3=VAR3;
run;
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.
Ready to level-up your skills? Choose your own adventure.