BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ChuksManuel
Pyrite | Level 9

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;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

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;

View solution in original post

4 REPLIES 4
SASKiwi
PROC Star

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;
andreas_lds
Jade | Level 19

@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

Patrick
Opal | Level 21

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;
ChuksManuel
Pyrite | Level 9

Thank you. That's exactly what i wanted to do

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 4 replies
  • 964 views
  • 1 like
  • 4 in conversation