BookmarkSubscribeRSS Feed
lmyers2
Obsidian | Level 7

Hello,

 

I'm using SAS 9.4 full edition via a virtual desktop. I have 71 co-morbidities and would like to find the most frequent ones.  I have shown 3 examples of below of how the variables are coded and then tried to code the array with these 3 example comorbidities. They aren't numbered 1-3 but rather have character coding that distinguish each comorbidity. Do I take the numbers out of the array?  Do I have to rename all of the variables?

 

CM_PULMCIRC
CM_RENLFAIL
CM_LIVER

 

data want; set have;
array CM_' ' [3] CM_' '1-CM_' '3;   
do i=1 to 3;
   if CM_' ' [i] > ' ' then do;
      diagnosis = CM_' '[i];
	output;
   end;
end;
keep diagnosis;
run;
proc freq order=freq; tables diagnosis; run;

 I 

3 REPLIES 3
art297
Opal | Level 21

You could use:

 

data want; set have;
  array _CM[3] CM_PULMCIRC CM_RENLFAIL CM_LIVER;   
  do i=1 to 3;
     if not missing(_CM[i]) then do;
        diagnosis = _CM[i];
        output;
     end;
  end;
  keep diagnosis;
run;

proc freq order=freq; tables diagnosis; run;

Art, CEO, AnalystFinder.com

 

Note: (12/31/2017 5:55pm) Removed an underscore that was inadvertently left in the array name. However, if you are interested in the variable names (as @PGStats mentioned), then change 

diagnosis = _CM[i];

to

diagnosis = vname(_CM[i]);

as he suggested.

 

PGStats
Opal | Level 21

Or rather

 

diagnosis = vname(_CM[i]);

PG
Tom
Super User Tom
Super User

Your question is a little confusing.  You talk about how the variables are coded but I think you meant how they are named.  How a variable is coded means the type, length and list or type of valid values.

 

If you have a series of variables that all start with the same characters you can use a colon ( : ) wildcard in the variable list for your array definition.  Just make sure that they are all of the same type (ie coded the same way). 

 

You can use the DIM() function to find out how many variables are in the array.

data want;
  set have;
  array _CM CM_: ;
  do i=1 to dim(_cm);
    if not missing(_cm(i)) then do;
      diagnosis = _cm(i);
      output;
    end;
  end;
keep diagnosis;
run;

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 3 replies
  • 696 views
  • 3 likes
  • 4 in conversation