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

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
  • 5 replies
  • 1613 views
  • 9 likes
  • 3 in conversation