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

I want to regroup numeric variable as another numeric variable, and the log produce log like below. How can I update my code to remove the NOTE.  Thanks.

NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).

 

data x;
do i=1 to 10;
	output;
end;
run;
proc format ;
	value num
		1-5 =1
		6-10 =2;
run;
data x2;
	set x;
	x=input(i, num.);
run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Describe what you are actually wanting to do in a bit more detail.

Your last data set actually gives more than the message you quoted:

17   data x2;
18      set x;
19      x=input(i, num.);
                   ----
                   485
NOTE 485-185: Informat NUM was not found or could not be loaded.

20   run;

NOTE: Numeric values have been converted to character values at the places given by:
      (Line):(Column).
      19:12

The INPUT function requires an informat which would be created in Proc format with and invalue statement. It also expects a text value for input, which is why it converted i to character and generated that message.

 

 

If you want to use the format to create a group use something that wants a group. You don't need to modify the value.

Consider:

proc freq data=x;
   tables i;
   format i num.;
run;

Typically conversion of numeric to numeric would use different logic depending on how complex the conversion might be.

One way as an example to look for values in a list of integers:

data x3;
	set x;
	If i in (1:5) then x=1;
   else if i in (6:10) then x=2;
run;

If your rules are complex enough to actually warrant an input then you use an INFORMAT like this:

Proc format;
invalue num
'1','2','3','4','5'=1
'6','7','8','9','10'=2
;

data x4;
  set x;
  x = input(put(i,best. -L),num.);
run;

The above uses an explicit PUT to control how the numeric value I is converted to character for use with the informat in the Input function. Note that the -L is to left justify the conversion to text for the number because the Invalue definition does not include any leading spaces which would then not get the expected result.

 

View solution in original post

4 REPLIES 4
ballardw
Super User

Describe what you are actually wanting to do in a bit more detail.

Your last data set actually gives more than the message you quoted:

17   data x2;
18      set x;
19      x=input(i, num.);
                   ----
                   485
NOTE 485-185: Informat NUM was not found or could not be loaded.

20   run;

NOTE: Numeric values have been converted to character values at the places given by:
      (Line):(Column).
      19:12

The INPUT function requires an informat which would be created in Proc format with and invalue statement. It also expects a text value for input, which is why it converted i to character and generated that message.

 

 

If you want to use the format to create a group use something that wants a group. You don't need to modify the value.

Consider:

proc freq data=x;
   tables i;
   format i num.;
run;

Typically conversion of numeric to numeric would use different logic depending on how complex the conversion might be.

One way as an example to look for values in a list of integers:

data x3;
	set x;
	If i in (1:5) then x=1;
   else if i in (6:10) then x=2;
run;

If your rules are complex enough to actually warrant an input then you use an INFORMAT like this:

Proc format;
invalue num
'1','2','3','4','5'=1
'6','7','8','9','10'=2
;

data x4;
  set x;
  x = input(put(i,best. -L),num.);
run;

The above uses an explicit PUT to control how the numeric value I is converted to character for use with the informat in the Input function. Note that the -L is to left justify the conversion to text for the number because the Invalue definition does not include any leading spaces which would then not get the expected result.

 

Patrick
Opal | Level 21
data x;
  do i=1 to 10;
    output;
  end;
run;

proc format;
  value num
    1-5  = 1
    6-10 = 2
    ;
run;

data x2;
  set x;
  x=input(put(i, num.),best32.);
run;
Tom
Super User Tom
Super User

You can eliminate that note by not using a number in a place where a string is required.

Formats convert values to text.  Informats convert text to values.

Numeric formats convert numbers to text. Numeric informats convert text to numbers.

Neither can convert numbers to numbers.

To convert numbers to numbers you need to either use a FUNCTION.  Or use a combination of a FORMAT and an INFORMAT.

 

So you have this format (although for some reason you left out the quotes around the strings)

proc format ;
value num
  1-5='1'
  6-10='2'
;
run;

So to use it to convert the number 5 to the number 1 you would need to do:

x=input(put(5, num.),32.);

 

Niugg2010
Obsidian | Level 7

Thanks everyone for help. At beginning, I thought input can regroup numeric variable to new numeric variable. Looks like I need to refresh myself with some basic functions.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 402 views
  • 0 likes
  • 4 in conversation