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 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
  • 2116 views
  • 0 likes
  • 2 in conversation