BookmarkSubscribeRSS Feed
Sujithpeta
Quartz | Level 8

Hello, 

DATA A.IP_Bene;
SET "/sas/raw4/WD1/ccaei121.sas7bdat";
	ARRAY ICD {15} DX1-DX15;
	DO i = 1 to 15;
		IF ICD {i} in ("45341", "45340", "45342", "45350", "45351", "45352", "45181", "45111", "45119", "41511", "41512", "41513", "41519") THEN DO; 
		OUTPUT; 
		LEAVE; 
		END;
	END;
RUN;

 

Above SAS code creates a dataset whos row have any of these strings ("45341", "45340", "45342", "45350", "45351", "45352", "45181", "45111", "45119", "41511", "41512", "41513", "41519") across 15 columns in the dataset.

How can I modify this code so that I can get count(No.of times the value appeared in the 15 columns) as following:

Description   Count

    45341          X

    45340          Y

    45342          Z

and so on....

 

Thanks

--Sujith

3 REPLIES 3
art297
Opal | Level 21

Do you want the overall counts for the file OR separately for each record?

 

Art, CEO, AnalystFinder.com

 

Sujithpeta
Quartz | Level 8

Overall Counts in the file.

 

Thanks

art297
Opal | Level 21

The following modification of your current code would do what you want:

 

DATA for_count (keep=_icd rename=(_icd=icd));
  SET ccaei121;
  ARRAY ICD {15} DX1-DX15;
  DO i = 1 to 15;
    IF ICD {i} in ("45341", "45340", "45342", "45350", "45351", "45352", "45181", "45111", "45119", "41511", "41512", "41513", "41519") THEN DO; 
      _icd=icd(i);
      OUTPUT; 
    END;
  END;
RUN;

proc freq data=for_count;
  tables icd;
run;

Art, CEO, AnalystFinder.com

 

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