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

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
PGStats
Opal | Level 21

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

View solution in original post

5 REPLIES 5
PGStats
Opal | Level 21

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
RichardinOz
Quartz | Level 8

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

Tal
Pyrite | Level 9 Tal
Pyrite | Level 9

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

Thank you both

RichardinOz
Quartz | Level 8

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

Tal
Pyrite | Level 9 Tal
Pyrite | Level 9

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 Smiley Happy

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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