- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
That did it! Thank you very much for the follow up and the help!