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;
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.