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
 

 

SAS Code for updating a record in the SAS Dataset

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> All Other Mainframe Topics
View previous topic :: :: View next topic  
Author Message
asimkp

New User


Joined: 24 Aug 2008
Posts: 4
Location: Bangalore,India

PostPosted: Wed Mar 30, 2011 10:40 pm    Post subject: SAS Code for updating a record in the SAS Dataset
Reply with quote

Hello,

I need some help for updating a record in SAS dataset.

Below are the details -
1. Copy the SAS Dataset
2. Update the record in one of the member of the SAS Dataset.

The structure of the member is pretty simple. It has only two columns(Variables) and 37 observation. I want to update the value for last record.

Currently, say the value for this record is
Code:
  COL1              COL2
  ABC                123


I want to update the value in col2 from 123 to 345.

I tried the following code, but in vain -

Code:
PROC COPY IN=INPUT1 OUT=OUTPUT1 MEMTYPE=ALL;   
RUN;                                           
DATA OUTPUT1.BAN;                           
 SET INPUT1.BAN;                           
  IF COL1 EQ 'ABC';                         
     COL2 = '345';                         
RUN;                                           


With this code, instead of copying all the 37 records from BAN, only the record 'ABC' is being copied with a value of 345.
Request you to please help me with this.
Back to top
View user's profile Send private message

Phrzby Phil

Active Member


Joined: 31 Oct 2006
Posts: 962
Location: Richmond, Virginia

PostPosted: Wed Mar 30, 2011 10:56 pm    Post subject:
Reply with quote

Your line
Code:
IF COL1 EQ 'ABC';

is called a subsetting IF. Only obs for which it is true continue with the next line; others resume at the top with the next obs.

You want


Code:

IF COL1 EQ 'ABC'
    THEN COL2 = '345';



This line runs for all obs, and only the ones passing the test have COL2 changed. Alll then continue to be written to the output.

This is a nice feature of SAS, but also an excellent example of the dangers lurking in SAS. What would be a syntax error in other languages (the ";" after the condition) is good SAS syntax, with the meaning I described.
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8593
Location: Back in jolly old England

PostPosted: Thu Mar 31, 2011 1:15 pm    Post subject:
Reply with quote

Well, first of all you did not state categorically that the value for COL1 would always be 'ABC' for the last record, nor did you state that 'ABC' could not be repeated within the sas dataset.

Of course you could have read the manual for data step options and found out all about the NOBS option.

As I'm in a really good mood today
Code:
data whatever;
 set whatever nobs=eof1;
 if _N_ = eof1 then col2 = 'xxx';
 output;
 run;
Back to top
View user's profile Send private message
asimkp

New User


Joined: 24 Aug 2008
Posts: 4
Location: Bangalore,India

PostPosted: Thu Mar 31, 2011 4:44 pm    Post subject: THANKS A LOT!!!
Reply with quote

Hello Phil & Expat,

Thanks a lot for all your help...
Removing the ';' has helped resolve the problem.

We can close this thread now.
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 Job failing with USER = 4093 REASON C... Pradeepa S ABENDS & Debugging 1 Wed May 17, 2017 3:35 pm
No new posts Fileaid 2 commands instream work. In ... descann Compuware & Other Tools 2 Tue May 16, 2017 3:31 pm
No new posts Adding big TEXT lines to each record ... bshkris SYNCSORT 4 Sat May 06, 2017 1:40 am
This topic is locked: you cannot edit posts or make replies. Merge two files and update Trailer re... Yashashri JCL & VSAM 1 Thu May 04, 2017 12:54 pm
No new posts COBOL Code Parsers and Lineage Establ... balimanja COBOL Programming 2 Tue May 02, 2017 3:30 am


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