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

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
Frequency

Cumulative
Percent

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 😞

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

View solution in original post

4 REPLIES 4
morgalr
Obsidian | Level 7
length g 3;
g=33;
p=put(g, 3.);
morgalr
Obsidian | Level 7

Oh, sorry you wanted to go the other way:

 

  length g $3;
  g='33';
  p=input(g, 3.);
ballardw
Super User

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.

Xinxin
Obsidian | Level 7

Thank you...this worked AND I learnt something new !

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
  • 1095 views
  • 1 like
  • 3 in conversation