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

Hello. I have data in the wide format. There are 5,530 variables for each observation that contain 0, 1, 2, 3, 4, or missing. Those numbers represent a type of location for healthcare services (e.g., 1 = in patient, 2 = emergency department). I am trying to use the COUNT function to get the frequency for each of those values (0-4) for each observation. So far, I am not able to get the correct count. 

 

To note, I did the simpler version of this and DID NOT specify which variables to count within, and I did get the correct number of those values, but that data step included those numbers from the PATID variable, which has 15-20 individual numbers.

 

Below is an example of the code for the data. Tos_Cd1 is the root variable name. There are 5,530 of these variables, hence the Tos_Cd11-Tos_Cd15530. Could someone please inform me where I can correct the code? Thank you!

 

data example1;

set example;

array string{*} Tos_Cd11-Tos_Cd15530;

  do i=1 to dim(string);

HCRU_Other=countc(string(i),'0');

HCRU_IP=countc(string(i),'1');

*and so on...;

end;

run;

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

When something does not run, go to the log, copy the log with the submitted code and any error or warning messages and paste into a code box opened using the forum's {I} icon. The code box is important to maintain formatting of error messages as the message window will reformat text. Many errors will have an _ character on the line below the code to indicate the position SAS determined the error occurred. The message windows will move that character reducing the usefulness of the log.

 

Since I did not have a data set with 20,000 variables laying around I miscopied the modified smaller example I tested:

 

Instead of

 HCRU_Other=countc(cats(of string(*),'0');

try

 HCRU_Other=countc(cats(of string(*)),'0');

The CATS function wasn't closed.

View solution in original post

4 REPLIES 4
ballardw
Super User

See if this helps:

data example1;
   set example;
   array string{*} Tos_Cd11-Tos_Cd15530;
  HCRU_Other=countc(cats(of string(*),'0');
  HCRU_IP=countc(cats(of string(*),'1');;
run;

This assumes that the 0, 1 or whatever only occurs once per variable.

 

The above code creates one string value from all of the variables and then counts the characters in the resulting combined string.

dwhitney
Calcite | Level 5

Thanks for the response. Unfortunately, it did not run.

 

I added another ")" (below), and was getting the following error: ERROR 71-185: The COUNTC function call does not have enough arguments. Any ideas why?

 

 

data example1;
   set example;
   array string{*} Tos_Cd11-Tos_Cd15530;
HCRU_Other=countc(cats(of string(*),'0'));
HCRU_IP=countc(cats(of string(*),'1')); run;

  

ballardw
Super User

When something does not run, go to the log, copy the log with the submitted code and any error or warning messages and paste into a code box opened using the forum's {I} icon. The code box is important to maintain formatting of error messages as the message window will reformat text. Many errors will have an _ character on the line below the code to indicate the position SAS determined the error occurred. The message windows will move that character reducing the usefulness of the log.

 

Since I did not have a data set with 20,000 variables laying around I miscopied the modified smaller example I tested:

 

Instead of

 HCRU_Other=countc(cats(of string(*),'0');

try

 HCRU_Other=countc(cats(of string(*)),'0');

The CATS function wasn't closed.

dwhitney
Calcite | Level 5

That did it! Thank you very much for the follow up and the help!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 4 replies
  • 1870 views
  • 0 likes
  • 2 in conversation