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

Ready to join fellow brilliant minds for the SAS Hackathon?

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

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 807 views
  • 1 like
  • 4 in conversation