BookmarkSubscribeRSS Feed
Aexor
Lapis Lazuli | Level 10

Can anyone tell me if have any proc , function or any option available with the help of that  we can modify a variable without reading the whole dataset in SAS.

 

It means we don't have  to read the whole data set just to modify few variables for e.g  Suppose we have 1 billion of record and for one small change we don't want to read whole records.

 

Thanks! 

3 REPLIES 3
maguiremq
SAS Super FREQ

What do you mean when you say modify? Look at PROC DATASETS. Might have your answer depending on what you mean by modify.

ballardw
Super User

What specific modifications do you have in mind?

Changing variable names, labels and formats can be done with Proc Datasets.

Replacing values can get into some details such as :

Does every value of XXX get changed to YYY or are the changes conditional?

If the changes are conditional then you need to describe the condition.

Is the variable character or numeric? If character what is the current defined length and the required length of the new value (can't stick 10 characters into a length 5 variable).

 

Answers to the above point to different possible solutions from UPDATE or MODIFY in data step or completely rebuilding possible rereading the data with custom informat or multiple IF/then/else or similar conditional logic.

If the answer is an EVERY value type change then perhaps no change is need to the data at all and may be handled by a custom format.

s_lassen
Meteorite | Level 14

You can do this with SQL or a data step.

 

SQL example:

proc sql;
  update lib.data1 set a=(select a2 from lib.data2 where id=data1.id) 
  where id in(select id from lib.data2 where salesdate>'01JAN2020'd)
 ;
quit;

Or the same thing in a data step:

data lib.data1;
  set lib.data2;
  where salesdate>'01JAN2020'd;
do until(0); modify lib.data1 key=id;
if _iorc_ then leave;
a=a2;
replace;
end; _error_=0; run;

The data step example as shown needs LIB.DATA1 to be indexed by ID. 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 499 views
  • 1 like
  • 4 in conversation