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: 965
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 Copy 4 byte of data from the last rec... arunsoods DFSORT/ICETOOL 9 Fri Oct 06, 2017 12:15 pm
No new posts opening a dataset after reading it fr... arunsoods DFSORT/ICETOOL 5 Wed Oct 04, 2017 3:54 pm
No new posts Speed-up/reduce CPU use of code prino PL/I & Assembler 0 Tue Sep 26, 2017 12:05 am
No new posts Updating the Trailer count in variabl... satheshbabur DFSORT/ICETOOL 6 Wed Aug 30, 2017 9:49 pm
No new posts Mainframe dataset split purushottam DFSORT/ICETOOL 13 Tue Aug 29, 2017 12:28 pm

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