IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Help with INPUT statement in SAS


IBM Mainframe Forums -> All Other Mainframe Topics
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
santosh_g

New User


Joined: 14 Aug 2011
Posts: 24
Location: india

PostPosted: Thu Jan 22, 2015 6:15 am
Reply with quote

Hello

Can anyone please help me understand why the output is like below:

The second record of Jone is also getting deleted from SAS dataset.

My understanding is that SAS is reading two records as one because of NUM2 being ".". How can I handle this (to remove Edgar and Include all Jone).

Code:

//SYSIN DD *

   DATA TEMP ;
   INPUT @001 EMPID     6.
         @007 EMPNAME  $10.
         @017 EMPAGE    2.
         @019 NUM       2. ;
   IF EMPNAME = 'EDGAR     '
     THEN DO ;
     INPUT @019 NUM2 2. ;
     DELETE ;
   END ;
   OUTPUT RI863B ;
      DATALINES;
043006JONE      3111
043006EDGAR     3211
043006EDGAR     3311
043006EDGAR     3411
043006EDGAR     3511
043006EDGAR     3611
043006JONE      3711
043006EDGAR     3811
043006EDGAR     3911
043006EDGAR     3011
043006EDGAR     4111
043006EDGAR     4211
043006EDGAR     4311
043006EDGAR     4411
    ;
   RUN ;

   PROC PRINT DATA=TEMP ;
   RUN ;



Output:


Code:

                  The SAS System                   
                                                   
 Obs    EMPID    EMPNAME    EMPAGE    NUM    NUM2   
                                                   
  1     43006     JONE        31       11      .   
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Thu Jan 22, 2015 8:44 am
Reply with quote

Quote:
My understanding is that SAS is reading two records as one because of NUM2 being ".".
Your understanding is very wrong. You are telling SAS to read from a separate line (record) every time it finds EMPNAME = 'EDGAR '. Hence it reads the first line and keeps it. The second line is read, then the third line is read inside the IF statement and all that data is deleted. The fourth line is read, then the fifth line is read inside the IF statement and again the data is deleted .... etc. SAS allows you to re-read a data line but you must use a trailing @ sign in your INPUT statement.

Something like this is what you want:
Code:
   DATA TEMP ;
   INPUT @001 EMPID     6.
         @007 EMPNAME  $10.
         @017 EMPAGE    2.
         @019 NUM       2. @ ;
   IF EMPNAME = 'EDGAR     '
     THEN DELETE ;
 
   OUTPUT RI863B ;
Why do you want to read columns 19-20 as 2 separate variables? NUM and NUM2 will have the same values every time.
Why do you read NUM2 and then immediately delete the observation?
Why do your DATA step and your OUTPUT have different names?

I would usually code this up as
Code:
INPUT @007 EMPNAME  $10. @ ;
IF EMPNAME =: 'EDGAR' THEN DELETE;
INPUT @001 EMPID    6.
      @017 EMPAGE   2.
      @019 NUM      2. ;
With SAS you don't have to read data from column 1 on - you can pick and choose. And I'll let you figure out the =: construct yourself (hint: it's in the SAS manual).
Back to top
View user's profile Send private message
santosh_g

New User


Joined: 14 Aug 2011
Posts: 24
Location: india

PostPosted: Thu Jan 22, 2015 8:59 am
Reply with quote

Thank you Robert.
Quote:
Your understanding is very wrong.

Yes. I am currently learning SAS and was testing few code. I am aware of reading data from any location. But I was not sure about @.

Thank you for your help & info.

Best Regards,
Back to top
View user's profile Send private message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1742
Location: Tirupur, India

PostPosted: Thu Jan 22, 2015 11:57 am
Reply with quote

Santhosh,

Robert already gave you the right info about using trailing @ to read a records more than once.
You showed how your input file looks like. If you could show us what exactly is the output for the above mentioned input datalines, then we could help you with the logic of SAS.

Regards,
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> All Other Mainframe Topics

 


Similar Topics
Topic Forum Replies
No new posts TRIM everything from input, output co... DFSORT/ICETOOL 1
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts force tablespace using LISTDEF input DB2 1
No new posts Two input files & writing counter... DFSORT/ICETOOL 12
No new posts Use input file with OMIT rcd keys? DFSORT/ICETOOL 15
Search our Forums:

Back to Top