BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
kmardinian
Quartz | Level 8

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):(Column).
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.
1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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

View solution in original post

4 REPLIES 4
Kurt_Bremser
Super User

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

Astounding
PROC Star

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

kmardinian
Quartz | Level 8

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!

ballardw
Super User

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.

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 4081 views
  • 2 likes
  • 4 in conversation