Hello,
Please, I need help adding row totals using the array statement. The problem with my code is that where are missing observations, it reports it as 0 instead of missing.
I need help resolving this issue. Please, find below my codes
Data Demo_DOSS_HighRiskMed4;
Set Demo_DOSS_HighRiskMed;
array DOSS_POS (*) $712 DOSS_POSITIVE1-DOSS_POSITIVE712 ( 0 1);
x1=whichc(1, of DOSS_POS[*]);
put x1=;
run;
Thank you for your assistance.
If "missing observations" means an observation where all variables have missing values, then all you have to do is test that beforehand.
Data Demo_DOSS_HighRiskMed4;
Set Demo_DOSS_HighRiskMed;
array DOSS_POS (*) $712 DOSS_POSITIVE1-DOSS_POSITIVE712 ( 0 1);
if n(of doss_pos[*])=0 then x1=.;
else x1=whichc(1, of DOSS_POS[*]);
put x1=;
run;
If "missing observations" means an observation where all variables have missing values, then all you have to do is test that beforehand.
Data Demo_DOSS_HighRiskMed4;
Set Demo_DOSS_HighRiskMed;
array DOSS_POS (*) $712 DOSS_POSITIVE1-DOSS_POSITIVE712 ( 0 1);
if n(of doss_pos[*])=0 then x1=.;
else x1=whichc(1, of DOSS_POS[*]);
put x1=;
run;
@UcheOkoro wrote:
Hello,
Please, I need help adding row totals using the array statement. The problem with my code is that where are missing observations, it reports it as 0 instead of missing.
I need help resolving this issue. Please, find below my codes
Data Demo_DOSS_HighRiskMed4; Set Demo_DOSS_HighRiskMed; array DOSS_POS (*) $712 DOSS_POSITIVE1-DOSS_POSITIVE712 ( 0 1); x1=whichc(1, of DOSS_POS[*]); put x1=; run;Thank you for your assistance.
Please note that you have NO test for "missing". The documentation for WHICHC, and WHICHN clearly state that if the value is not found that the function returns zero for a value.
I bet you also have messages about "converting numeric to character" in your log. If the values are actually character 0 and 1 you should reference them as '0' and '1'.
Do you actually have 712 variables each of 712 character length?
If the variables you want to use already exist you do not need to provide a length or type.
array DOSS_POS (*) DOSS_POSITIVE1-DOSS_POSITIVE712 ;
Should work just fine.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.