BookmarkSubscribeRSS Feed
Dhana18
Obsidian | Level 7

Pleasse tell me what is wrong with this code?

DATA MarchNin.MERGE_March2019_P;
SET MarchNin.MERGE_March2019_O;
IF HIV_COMBON_A ="N" OR HIV_1_2_ABBLOOD ="N" OR HIV_GEENION_A="N" OR HIV_PCRN_A="N" THEN GISP_HIVRESULT ="0";
ELSE IF HIV_COMBON_A ="A" OR HIV_1_2_ABBLOOD ="A" OR HIV_GEENION_A="A" OR HIV_PCRN_A="A" THEN GISP_HIVRESULT ="9";
ELSE IF HIV_COMBON_A="P" OR HIV_1_2_ABBLOOD="P" OR HIV_GEENION_A="P" OR HIV_PCRN_A="P" THEN GISP_HIVRESULT ="1";
ELSE GISP_HIVRESULT ="7";
RUN;

PROC FREQ DATA=MarchNin.MERGE_March2019_P;
TABLE GISP_HIVRESULT;
RUN;

 

Here is the result:

GISP_HIVRESULT Frequency Percent CumulativeFrequency CumulativePercent079
24164.6124164.61
12834.3236998.93
41.07373100.00

 Why am I not getting only 0, 7, and 9 and not 1 under GISP_HIVRESULT?  Please help.

2 REPLIES 2
PGStats
Opal | Level 21

Proc freq only presents to you the frequencies that occur in your data. It does not include zeros for values that could have been present but that didn't occur in your data.

PG
Dhana18
Obsidian | Level 7

Thank you. I modified the  like this and it worked.

DATA MarchNin.MERGE_March2019_P;
SET MarchNin.MERGE_March2019_O;
IF HIV_COMBON_A="P" THEN GISP_HIVRESULT ="1";
else IF HIV_COMBON_A ="N" OR HIV_1_2_ABBLOOD ="N" OR HIV_GEENION_A="N" OR HIV_PCRN_A="N" THEN GISP_HIVRESULT ="0";
ELSE IF HIV_COMBON_A ="A" OR HIV_1_2_ABBLOOD ="A" OR HIV_GEENION_A="A" OR HIV_PCRN_A="A" THEN GISP_HIVRESULT ="9";
ELSE GISP_HIVRESULT ="7";
RUN;

I did not have response "P" in all variables. 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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