Hi...I am trying to fill in the Major variable with the first non-missing entry until the next non-missing entry (its possible for the same StudentUID to have more than one major) and I am getting an error message that the variable Major is both character and numeric. Major is character with length 50 and StudentUID is numeric. If I exclude the "not missing(Major or" from the until statement, it executes but I don't get the proper output. Can anyone see why I am getting the error message....Thanks.
data StudentDegree1;
length a1 $50;
do until(not missing(Major) or last.StudentUID);
set StudentDegree2;
by StudentUID Major notsorted;
a1=Major;
end;
do until(not missing(Major) or last.StudentUID);
set StudentDegree2;
by StudentUID Major notsorted;
Major=a1;
output;
end;
drop a1;
run;
Log Output:
NOTE: There were 153022 observations read from the data set WORK.STUDENTDEGREE2.
NOTE: The data set WORK.STUDENTDEGREE2 has 153022 observations and 7 variables.
NOTE: PROCEDURE SORT used (Total process time):
real time 0.32 seconds
cpu time 0.51 seconds
319
320 data StudentDegree1;
321 length a1 $50;
322 do until(not missing(Major) or last.StudentUID);
323 set StudentDegree2;
ERROR: Variable Major has been defined as both character and numeric.
324 by StudentUID Major notsorted;
325 a1=Major;
326 end;
327 do until(not missing(Major) or last.StudentUID);
328 set StudentDegree2;
ERROR: Variable Major has been defined as both character and numeric.
329 by StudentUID Major notsorted;
330 Major=a1;
331 output;
332 end;
333 drop a1;
334 run;
While I can't check it right now, I'm guessing that the DO UNTIL loop defines MAJOR as numeric. To get around that, add this right after the LENGTH statement:
if 5=4 then set StudentDegree2;
Even though it never executes (obviously, 5 does not equal 4), its presence is enough to define all the variables in StudentDegree2.
Can you provide some example data so we can test your code?
Hi...I have included a dataset below....
data Have;
length StudentUID 8 Major $ 50 TextTerm $ 12;
format StudentUID BEST12. Major $CHAR50. TextTerm $CHAR12.;
informat StudentUID BEST12. Major $CHAR50. TextTerm $CHAR12.;
infile datalines4 dlm='7F'x missover dsd;
input StudentUID : BEST32. Major : $CHAR50. TextTerm : $CHAR12.;
datalines4;
104 00-01 Trm 1C
104Industrial Maintenance Technician00-01 Trm 2C
104Industrial Maintenance Technician00-01 Trm 3C
105Production Art00-01 Trm 1C
106Cisco Training00-01 Trm 3C
106 00-01 Trm 1C
106 00-01 Trm 2C
106Microcomputer Systems Technician00-01 Trm 2C
107Auto Mechanics00-01 Trm 2C
107 00-01 Trm 3C
108 00-01 Trm 2C
108Microcomputer Systems Technician00-01 Trm 3C
108Cisco Training01-02 Trm 2C
108 01-02 Trm 3C
109Microcomputer Systems Technician00-01 Trm 2C
109 01-02 Trm 1C
109 01-02 Trm 2C
109Cisco Training01-02 Trm 2C
;;;;
While I can't check it right now, I'm guessing that the DO UNTIL loop defines MAJOR as numeric. To get around that, add this right after the LENGTH statement:
if 5=4 then set StudentDegree2;
Even though it never executes (obviously, 5 does not equal 4), its presence is enough to define all the variables in StudentDegree2.
Hi Astounding....I did try your suggestions and it worked....thanks a ton!!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: