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

SAS Code for updating a record in the SAS Dataset


IBM Mainframe Forums -> All Other Mainframe Topics
Post new topic   Reply to topic
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
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

Senior Member


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

PostPosted: Wed Mar 30, 2011 10:56 pm
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: 8797
Location: Welsh Wales

PostPosted: Thu Mar 31, 2011 1:15 pm
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> All Other Mainframe Topics

 


Similar Topics
Topic Forum Replies
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts run rexx code with jcl CLIST & REXX 15
No new posts Compile rexx code with jcl CLIST & REXX 6
No new posts FINDREP - Only first record from give... DFSORT/ICETOOL 3
Search our Forums:

Back to Top