NOTE: Character values have been converted to numeric values

Accepted Solution Solved
Reply
Contributor
Posts: 32
Accepted Solution

NOTE: Character values have been converted to numeric values

LOG:

 

108
109 Data MCAssign2;
110 Set MCCAssign1 (keep= ID ctAlteration Alteration protocol);
111 IDchar = put(ID, $24.);
112 drop ID;
113 rename IDchar=ID;
114 Run;
 
NOTE: There were 30871 observations read from the data set WORK.MCCASSIGN1.
NOTE: The data set WORK.MCASSIGN2 has 30871 observations and 4 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.02 seconds
 
 
115
116
117 Data Final (drop=a ct);
118 do until (last.ID);
119 set MCCAssign1;
120 By MRN;
121 if not missing (alteration) then a='1';
122 if not missing(ctalteration) then ct='1';
123 end;
124 do until (last.ID);
125 set MCCAssign1;
126 by ID;
127 if a and ct then output;
128 end;
129 Run;
 
NOTE: Character values have been converted to numeric values at the places given by: (Line)Smiley SadColumn).
127:4 127:10
NOTE: There were 30871 observations read from the data set WORK.MCCASSIGN1.
NOTE: There were 30871 observations read from the data set WORK.MCCASSIGN1.
NOTE: The data set WORK.FINAL has 5767 observations and 4 variables.
NOTE: DATA statement used (Total process time):
real time 0.02 seconds
cpu time 0.01 seconds
 
 
130
131 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
144
 
Hi, so I've been having issues with my character values being converted to numeric. This causes my "Final" dataset to only have 5767 observations, down from  30,871 observations, which is a lot of observations I am losing. I have tried converting ID to a character variable, but I don't think it ended up working. Any help is much appreciated.

Accepted Solutions
Solution
‎10-25-2017 05:27 PM
Super User
Posts: 8,062

Re: NOTE: Character values have been converted to numeric values

Posted in reply to kmardinian

Variables used as boolean have to be numeric. 0 = false, non-zero values = true. So assign 0 or 1 instead of '0' and '1'.

 

About your exclusion problem: find observations that should be included but aren't, and run them through your code "manually" (pencil&paper).

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Solution
‎10-25-2017 05:27 PM
Super User
Posts: 8,062

Re: NOTE: Character values have been converted to numeric values

Posted in reply to kmardinian

Variables used as boolean have to be numeric. 0 = false, non-zero values = true. So assign 0 or 1 instead of '0' and '1'.

 

About your exclusion problem: find observations that should be included but aren't, and run them through your code "manually" (pencil&paper).

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 5,610

Re: NOTE: Character values have been converted to numeric values

[ Edited ]
Posted in reply to kmardinian

You have a critical typo in the program.  Your top loop :

 

Do until (last.ID);

 

But inside the loop, the BY statement reads:

 

BY MRN;

 

Those are not consistent, and illogical.  The only reason you get no error message is because of the bottom DO loop, which actually does create last.ID.

 

Also, note that @KurtBremser is correct.  If you don't want variables convered to numeric, a good solution is often to create them as numeric yourself:

 

if ...... then a=1;

if ....... then ct=1;

 

Once you put quotes around the "1" you are creating them as character, which later forces SAS to convert them back to numeric.

Contributor
Posts: 32

Re: NOTE: Character values have been converted to numeric values

Posted in reply to Astounding

Yes, definitely fixed that typo and removed the quotations and that part of the code is working. I'm currently going through the data manually to see which values are not being read. This way I can try and figure out why I'm losing so many observations

Thank you for all the help!

Super User
Posts: 11,563

Re: NOTE: Character values have been converted to numeric values

Posted in reply to kmardinian

A useful bit of SAS coding knowledge:

Instead of

 if not missing (alteration) then a='1';

you can use

a = not missing (alteration);

 

It's easy to create Boolean values:

data junk;
   input x;
   a= not missing(x);
   b = x ge 3;
datalines;
1
.
3
44
;
run;

Just be sure that if only want a value when a certain condition occurs that you have and IF / then assignment otherwise every record has either 0 or 1.

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 106 views
  • 1 like
  • 4 in conversation