BookmarkSubscribeRSS Feed
emma19901
Calcite | Level 5

Hi, I have a database with character observations ( y and n) I want to assign them values to calculate the comorbidity index. The code I am using is the following with no result.

 

data hw2;
 set datasets.riskdata;
 array a {5} cbypass cbv_ds respprob neuropthy pvd;
 do i=1 to 5;
 if a{i}= y then a{i}=1;
 end;
 run;
 
NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
84:17
NOTE: Variable y is uninitialized.
NOTE: There were 830 observations read from the data set DATASETS.RISKDATA.
NOTE: The data set WORK.HW2 has 830 observations and 14 variables.
NOTE: DATA statement used (Total process time):
real time 0.02 seconds
cpu time 0.01 seconds
 
Also I am trying to use arrays to erase missing values with this code but is also not working.
 
 

data hw2;
set datasets.riskdata;
if diagnosis= 'TYPE1_DM' then diagnosis='2';
if diagnosis='TYPE2_DM' THEN DIAGNOSIS='0';
if diagnosis= 'PXECTMY'  then diagnosis='0';
IF los<0 then los=.;
array a{9} diagnosis dialysis cbypass cbv_ds respprob neuropthy mi pvd lipiddis;
do i=1 to 9;
if a{i}= ' ' then a{i}=delete;
end;
run;

2 REPLIES 2
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

 

data hw2;
 set datasets.riskdata;
 array a {5} cbypass cbv_ds respprob neuropthy pvd;
 do i=1 to 5;
 if uppercase(a{i})= 'Y' then a{i}=1;
 end;
 run;
 

 

Astounding
PROC Star

For your first question, you will need to define a new set of variables.  Character variables won't hold numeric values.  One possibility:

 

data hw2;
 set datasets.riskdata;
 array a {5} cbypass cbv_ds respprob neuropthy pvd;
 array b {5} cbypass_num cbv_ds_num respprob_num neuropthy_num pvd_num;
 do i=1 to 5;
 if upcase(a{i})= "Y" then b{i}=1;
 else b{i}=0;
 end;
 run;
 
Notice that when you omit the quotes, y refers to a variable name.  When you add quotes, "Y" refers to a character string.  This will impact your second question where you check whether a variable is equal to delete.  With no quotes, delete is the name of a variable.  Clearly, this is not the comparison you want to make.  However, your objective in the second DATA step is not clear.  What are you trying to accomplish?  Describe the results you want, don't show a program.  It's really not clear what you want when you say "erase missing values".

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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