Hello,
How can I achieve the following?
One record with many different fields.
DATA ACT.TMP; );
INFILE INDB MISSOVER;
INPUT
@0100 ACCT13 7. /*ACCOUNT NUMBER */
@0238 TOTEX12 PD008.3 /*ACT-AR-EXPSR-120-AM */
@0246 TOTEX15 PD008.3 /*ACT-AR-EXPSR-150-AM */
@0415 ANNVDT PD004. /*ACT-ANNIV-DT */
;
I want to write this out like the following and assign a new variable to each different value:
ACCT13 New Var
1234567 Z0033 345.00 This record for TOTEX12
1234567 Z0005 622.00 This record for TOTEX15
1234567 Z0010 2013200 This record for ANNIVDT
8765432 Z0033 150.00 This record for TOTEX12
8765432 Z0005 80.00 This record for TOTEX15
8765432 Z0010 2013188 This record for ANNIVDT
......etc....
Any suggestions on how to accomplish this??
Try something like this. Note that I am assuming that all the input variables in ACT.TMP are numeric.
data accounts (keep=account newvar vardesc varvalue);
set act.tmp ;
rename acct13 = account;
array tmp{3} totex12 totex15 annivdt ;
do j = 1 to 3 ;
if tmp{j} ne . then do;
varvalue = tmp{j};
if j = 1 then do ;
vardesc = 'TOTEX12';
newvar = 'Z0033';
end;
else if j = 2 then do ;
vardesc = 'TOTEX15';
newvar = 'Z0005';
end;
else if j = 3 then do ;
vardesc = 'ANNIVDT';
newvar = 'Z0010';
end;
output;
end;
end;
run;
The way you show your results doesn't quite match the discription of "a new variable to each different value". The appearance suggests one variable whose value changes between Z0033, Z0005 and Z0010. Do want to create a new dataset or actually write to output or an ODS destination?
I want to create a new dataset. I want to define a new Zcode based on each variable. Ex. All TOTEX12 will have a Zcode of Z0033 - All TOTEX15 will have a Zcode of Z0005, etc...
Maybe my terminology is not quite correct.
Try something like this. Note that I am assuming that all the input variables in ACT.TMP are numeric.
data accounts (keep=account newvar vardesc varvalue);
set act.tmp ;
rename acct13 = account;
array tmp{3} totex12 totex15 annivdt ;
do j = 1 to 3 ;
if tmp{j} ne . then do;
varvalue = tmp{j};
if j = 1 then do ;
vardesc = 'TOTEX12';
newvar = 'Z0033';
end;
else if j = 2 then do ;
vardesc = 'TOTEX15';
newvar = 'Z0005';
end;
else if j = 3 then do ;
vardesc = 'ANNIVDT';
newvar = 'Z0010';
end;
output;
end;
end;
run;
Fugue,
Thank you very much for your response. It works just fine.
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.