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

## put and input

hi guys,

i dont understand the bold commands below.Shouldn't that be INPUT instead?

Please someone explain to me

PROC FORMAT;

VALUE \$GENDER 'F','M' = 'Valid'

' '     = 'Missing'

OTHER   = 'Miscoded';

VALUE \$DX '001' - '999' = 'Valid'

' '           = 'Missing'

OTHER     = 'Miscoded';

VALUE \$AE '0','1' = 'Valid'

' '     = 'Missing'

OTHER  = 'Miscoded';

RUN;

DATA _NULL_;

INFILE "C:\CLEANING\PATIENTS.TXT" PAD;

FILE PRINT; ***Send output to the output window;

TITLE "Listing of Invalid Patient Numbers and Data Values";

***Note: We will only input those variables of interest;

INPUT @1 PATNO    \$3.

@4 GENDER   \$1.

@24 DX       \$3.

@27 AE       \$1.;

IF PUT(GENDER,\$GENDER.) = 'Miscoded' THEN PUT PATNO= GENDER=;

IF PUT(DX,\$DX.) = 'Miscoded' THEN PUT PATNO= DX=;

IF PUT(AE,\$AE.) = 'Miscoded' THEN PUT PATNO= AE=;

RUN;

1 ACCEPTED SOLUTION

Accepted Solutions
Opal | Level 21

## Re: put and input

PUT(<var>, <format>) is a function that transforms the internal value of <var> into a string using the format <format>, INPUT(<string>,<informat>) transforms <string> into an internal value using input format <informat>. Not to be confused with the PUT and INPUT statements which are commands that do not return a value.

PG

PG
5 REPLIES 5
Opal | Level 21

## Re: put and input

PUT(<var>, <format>) is a function that transforms the internal value of <var> into a string using the format <format>, INPUT(<string>,<informat>) transforms <string> into an internal value using input format <informat>. Not to be confused with the PUT and INPUT statements which are commands that do not return a value.

PG

PG
Quartz | Level 8

## Re: put and input

You can use INPUT( ) in this case but then the formats need to be defined as informats.

PROC FORMAT;

INVALUE \$GENDER 'F','M' = 'Valid'

' '     = 'Missing'

OTHER   = 'Miscoded';

INVALUE \$DX '001' - '999' = 'Valid'

' '           = 'Missing'

OTHER     = 'Miscoded';

INVALUE \$AE '0','1' = 'Valid'

' '     = 'Missing'

OTHER  = 'Miscoded';

RUN;

DATA _NULL_;

INFILE "C:\CLEANING\PATIENTS.TXT" PAD;

FILE PRINT; ***Send output to the output window;

TITLE "Listing of Invalid Patient Numbers and Data Values";

***Note: We will only input those variables of interest;

INPUT @1 PATNO    \$3.

@4 GENDER   \$1.

@24 DX       \$3.

@27 AE       \$1.;

IF INPUT(GENDER,\$GENDER.) = 'Miscoded' THEN PUT PATNO= GENDER=;

IF INPUT(DX,\$DX.) = 'Miscoded' THEN PUT PATNO= DX=;

IF INPUT(AE,\$AE.) = 'Miscoded' THEN PUT PATNO= AE=;

RUN;

But most of us would not bother.

Key thing to remember: PUT( ) accepts numeric or string arguments, but always returns a string value

INPUT( ) always requires a string argument, but can return a numeric or string return value, based on the informat.

Richard in Oz

Pyrite | Level 9

## Re: put and input

oh so this just answered my 2nd question to PG.

Thank you both

Quartz | Level 8

## Re: put and input

So both functions can be used to convert a string value into another string value. but neither can be used to convert a numeric value to another numeric value. if you ever need to do that you would have to concatenate, using a format that returns a string that looks like a number,

new_newmeric = input(put(prev_number, somefmt.), best.) ;

Richard in Oz

Pyrite | Level 9

## Re: put and input

sorry do you by "transforms the internal value of <var> into a string" mean converts the numeric value of var into a char value? All i know about put and input is that the first converts numeric to char using a certain format and the latter the other way around

Discussion stats
• 5 replies
• 1611 views
• 9 likes
• 3 in conversation