Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist 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: 972
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: 8657
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 VSAM - Accessing beyond record size Benchwarmer JCL & VSAM 6 Wed Apr 11, 2018 9:20 pm
No new posts Getting GG return code abdulrafi IMS DB/DC 2 Tue Apr 10, 2018 12:31 pm
No new posts How could i share my personal dataset... James Halley TSO/ISPF 1 Fri Mar 23, 2018 9:41 pm
This topic is locked: you cannot edit posts or make replies. How could i share my personal dataset... samenxia163 TSO/ISPF 1 Fri Mar 09, 2018 12:18 pm
No new posts IMS error U4038 while executing my PL... abdulrafi IMS DB/DC 2 Thu Feb 08, 2018 1:05 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us