DATA Step, Macro, Functions and more

put and input

Accepted Solution Solved
Reply
Super Contributor
Super Contributor
Posts: 444
Accepted Solution

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;


Accepted Solutions
Solution
‎11-16-2012 09:47 PM
Respected Advisor
Posts: 4,919

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

View solution in original post


All Replies
Solution
‎11-16-2012 09:47 PM
Respected Advisor
Posts: 4,919

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
Super Contributor
Posts: 644

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

Super Contributor
Super Contributor
Posts: 444

Re: put and input

Posted in reply to RichardinOz

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

Thank you both

Super Contributor
Posts: 644

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

Super Contributor
Super Contributor
Posts: 444

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

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

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