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:
| 241 | 64.61 | 241 | 64.61 |
| 128 | 34.32 | 369 | 98.93 |
| 4 | 1.07 | 373 | 100.00 |
Why am I not getting only 0, 7, and 9 and not 1 under GISP_HIVRESULT? Please help.
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.
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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.