BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
UcheOkoro
Lapis Lazuli | Level 10

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.

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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;

 

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

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;

 

--
Paige Miller
ballardw
Super User

@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.

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
  • 846 views
  • 0 likes
  • 3 in conversation