I'm trying to change "education" to numeric. Tried all different ways, hence code in comments.
PROC FREQ DATA=XYZ1; TABLES EDUCATION; RUN;
The FREQ Procedure
education |
||||
education |
Frequency |
Percent |
Cumulative |
Cumulative |
college grad |
22 |
17.46 |
22 |
17.46 |
grade or less |
6 |
4.76 |
28 |
22.22 |
some college |
32 |
25.40 |
60 |
47.62 |
some high or tech school;high or tech school graduate |
66 |
52.38 |
126 |
100.00 |
Frequency Missing = 3 |
PROC FORMAT;
VALUE $EDU
/*
1="grade or less"
2="some high or tech school;high or tech school graduate"
3="some college"
4="college grad";
*/
"grade or less" = 1
"some high or tech school;high or tech school graduate" =2
"some college"=3
"college grad"=4
;
RUN;
DATA XYZ2; SET XYZ1; FORMAT EDUCATION EDU. ;
*EDUCATION=INPUT(EDUCATION, 8.);
RUN;
DATA XYZ3; SET XYZ2; EDUCATION1=INPUT(EDUCATION, 8.);
RUN;
The note is:
NOTE: Invalid argument to function INPUT at line 166 column 35.
Seems like such a simple thing, but I can't get it 😞
Try:
PROC FORMAT; inVALUE EDU /*INVALUE makes an informat to use with INPUT*/ "grade or less" = 1 "some high or tech school;high or tech school graduate" =2 "some college"=3 "college grad"=4 ; run; DATA XYZ3; SET XYZ2; EDUCATION1=INPUT(EDUCATION, EDU.); RUN;
Input statement is going to require an informat, custom ones are made with the INVALUE in proc format.
Note that spelling must match exactly including leading spaces and such. Case differences can be addressed with UPCASE option and the values as upper case.
Also to create a numeric value the Invalue does not start with $. You would use that create a different text value from existing text.
And last, the INPUT statement uses the Informat you created to read the text.
length g 3; g=33; p=put(g, 3.);
Oh, sorry you wanted to go the other way:
length g $3; g='33'; p=input(g, 3.);
Try:
PROC FORMAT; inVALUE EDU /*INVALUE makes an informat to use with INPUT*/ "grade or less" = 1 "some high or tech school;high or tech school graduate" =2 "some college"=3 "college grad"=4 ; run; DATA XYZ3; SET XYZ2; EDUCATION1=INPUT(EDUCATION, EDU.); RUN;
Input statement is going to require an informat, custom ones are made with the INVALUE in proc format.
Note that spelling must match exactly including leading spaces and such. Case differences can be addressed with UPCASE option and the values as upper case.
Also to create a numeric value the Invalue does not start with $. You would use that create a different text value from existing text.
And last, the INPUT statement uses the Informat you created to read the text.
Thank you...this worked AND I learnt something new !
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: