BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
BruceBrad
Lapis Lazuli | Level 10

I'm trying to recode some character values into numeric values. Here is some code that doesn't work. What have I done wrong?

proc format;

  invalue testf  'A'  'B' = 1  'C'  'D' = 0;

run;

data _null_;

chr='A';

num = input(chr,testf.);

run;

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

How about:

proc format;

  invalue    testf

   'A' ,'B' = 1

   'C' ,'D' = 0;

run;

data temp;

chr='A';

num = input(chr,testf.);

run;

Ksharp

View solution in original post

3 REPLIES 3
Ksharp
Super User

How about:

proc format;

  invalue    testf

   'A' ,'B' = 1

   'C' ,'D' = 0;

run;

data temp;

chr='A';

num = input(chr,testf.);

run;

Ksharp

BruceBrad
Lapis Lazuli | Level 10

Thanks. The curious thing about this is that proc format without the required commas does not give an error message. The error only occurs when I use the incorrect format in the data step. And a very unhelpful message too:

NOTE: Invalid argument to function INPUT at line 38 column 7.

chr=A num=. _ERROR_=1 _N_=1

NOTE: Mathematical operations could not be performed at the following places. The results of

      the operations have been set to missing values.

(I'm using version 9.3)

data_null__
Jade | Level 19

You don't get an error because the code is correct.  The value/invalue statements have implied concatenation, which is most useful if you need to use two different types of constants.  For example a character constant followed by a HEX constant.  "Hello' 'F2'x 

You can see how PROC FORMAT processed your statements by adding the FMTLIB option.

----------------------------------------------------------------------------

|     INFORMAT NAME: @TESTF   LENGTH:    2   NUMBER OF VALUES:    2        |

|   MIN LENGTH:   1  MAX LENGTH:  40  DEFAULT LENGTH   2  FUZZ:        0   |

|--------------------------------------------------------------------------|

|START           |END             |INVALUE(VER. V7|V8   10OCT2011:06:40:11)|

|----------------+----------------+----------------------------------------|

|AB              |AB              |                                       1|

|CD              |CD              |                                       0|

----------------------------------------------------------------------------

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 3 replies
  • 996 views
  • 0 likes
  • 3 in conversation