Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Help with INPUT statement in SAS

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> All Other Mainframe Topics
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    Post subject: Help with INPUT statement in SAS
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: 7912
Location: Bellevue, IA

PostPosted: Thu Jan 22, 2015 8:44 am    Post subject:
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    Post subject:
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: 1445
Location: Azeroth

PostPosted: Thu Jan 22, 2015 11:57 am    Post subject:
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    IBMMAINFRAMES.com Support Forums -> All Other Mainframe Topics All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Performing arithmetic on input field zh_lad DFSORT/ICETOOL 3 Tue Dec 06, 2016 8:04 pm
No new posts High CPU consumption Job using IAM fi... aswinir JCL & VSAM 8 Thu Dec 01, 2016 8:28 pm
No new posts -913/-911 Deadlock during UPDATE stat... NoSleep319 DB2 5 Fri Nov 18, 2016 12:37 am
This topic is locked: you cannot edit posts or make replies. How to use 2 input files in control c... Gunapala CN DFSORT/ICETOOL 23 Thu Oct 13, 2016 3:42 pm
No new posts COBOL DB2 - CALL statement - high CPU... TS70363 DB2 15 Sun Sep 11, 2016 6:07 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us