Hi guys,
I'm trying to use an array to string out variables in my dataset and create a manuscript table.
Can any help me review this code? I want the stringed variable to appear in the order as in the array. The code was not running well.
proc format;
value danfm
1= 'age'
2= 'gender'
3= 'obesity'
4= 'hlth'
5= 'smoke1'
6= 'smoke2'
7= 'smoke3'
;
data me; set you;
array her age gender obesity hlth smoke1 smoke2 smoke3;
do over her;
tc=_I_;
tn= put (tc,danfm.);
value=her;
output; end;
data me1; set me; if value ne .; run;
Here some code addressing what I'm guessing you're asking for.
data have;
array her {*} 8 age gender obesity hlth smoke1 smoke2 smoke3 (6*1);
output;
smoke2=.;
smoke3=99;
output;
stop;
run;
proc format;
value danfm
1= 'age'
2= 'gender'
3= 'obesity'
4= 'hlth'
5= 'smoke1'
6= 'smoke2'
7= 'smoke3'
;
data me;
set have;
array her {*} age gender obesity hlth smoke1 smoke2 smoke3;
do tc=1 to dim(her);
tn= put (tc,danfm.);
value=her[tc];
if not missing(value) then output;
end;
drop age gender obesity hlth smoke1 smoke2 smoke3;
run;
Reading the documentation on the ARRAY statement will help you get the syntax right.
I've no idea what you are trying to do in your program and you don't provide any data to test but this is the correct syntax:
array her (*) age gender obesity hlth smoke1 smoke2 smoke3;
@SASKiwi wrote:
Reading the documentation on the ARRAY statement will help you get the syntax right.
I've no idea what you are trying to do in your program and you don't provide any data to test but this is the correct syntax:
array her (*) age gender obesity hlth smoke1 smoke2 smoke3;
@ChuksManuel: The array statement will be of use only, if all variable have the same type. I doubt that "age" is alphanumeric
Here some code addressing what I'm guessing you're asking for.
data have;
array her {*} 8 age gender obesity hlth smoke1 smoke2 smoke3 (6*1);
output;
smoke2=.;
smoke3=99;
output;
stop;
run;
proc format;
value danfm
1= 'age'
2= 'gender'
3= 'obesity'
4= 'hlth'
5= 'smoke1'
6= 'smoke2'
7= 'smoke3'
;
data me;
set have;
array her {*} age gender obesity hlth smoke1 smoke2 smoke3;
do tc=1 to dim(her);
tn= put (tc,danfm.);
value=her[tc];
if not missing(value) then output;
end;
drop age gender obesity hlth smoke1 smoke2 smoke3;
run;
Thank you. That's exactly what i wanted to do
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: