BookmarkSubscribeRSS Feed
jhusoc
Obsidian | Level 7

Hello,

 

I would like to add value to an existing row. 

 

For example, I have a table,

data mydata;
    input num1 num2 mydate date9.;
    format mydate date9.;
    datalines;
1200 50000 05MAY1985
0 0 17AUG1982
1500 43500 23OCT1991
;
run;

the output:

Obs num1 num2 mydate123
12005000005MAY1985
0017AUG1982
15004350023OCT1991

The second row has 0 and 0. I want to change 0,0 to 1700, 60000. Can I do that use SAS?

Thank you all,

 

JH

6 REPLIES 6
jhusoc
Obsidian | Level 7
The real dataset is huge. I cannot make a new table to replace the current one. I just want to add the values to the table. Thanks.
PeterClemmensen
Tourmaline | Level 20

Sounds like you want to use the Modify Statement

ballardw
Super User

@jhusoc wrote:

Hello,

 

I would like to add value to an existing row. 

 

For example, I have a table,

data mydata;
    input num1 num2 mydate date9.;
    format mydate date9.;
    datalines;
1200 50000 05MAY1985
0 0 17AUG1982
1500 43500 23OCT1991
;
run;

the output:

Obs num1 num2 mydate123
1200 50000 05MAY1985
0 0 17AUG1982
1500 43500 23OCT1991

The second row has 0 and 0. I want to change 0,0 to 1700, 60000. Can I do that use SAS?

Thank you all,

 

JH


In your "real" data is it only one record or multiple that need this change?

If more than one record, do they all have the same change or different?

Do you have a variable, or combination of variables, that uniquely identify this record (or other records that need change)?

jhusoc
Obsidian | Level 7
Currently. I just have one row that needs to change. But if I know how to change multiple rows, it'll be excellent!
If more than one change, they'll be different.
Yes. I have a unique variable for changing the records.

Thank you!
LeonidBatkhan
Lapis Lazuli | Level 10

Hi jhusoc,

 

This may not be the most efficient way to do it, but it is perhaps the simplest:

data mydata;
    input num1 num2 mydate date9.;
    format mydate date9.;
    datalines;
1200 50000 05MAY1985
0 0 17AUG1982
1500 43500 23OCT1991
;
data mydata;
   set mydata;
   if _n_=2 then
   do;
      num1 = 1700;
num2 = 60000; end; run;

Hope this helps.

ChrisNZ
Tourmaline | Level 20

Probably not what you need, but since you haven't explained your need on the full data set, this does what you asked for:

data mydata;
  input NUM1 NUM2 MYDATE date9.;
  format MYDATE date9.;
  if NUM1=0 then NUM1=1700;
  if NUM2=0 then NUM1=60000;
  datalines;
1200 50000 05MAY1985
0 0 17AUG1982
1500 43500 23OCT1991
run;

 

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 6 replies
  • 759 views
  • 0 likes
  • 5 in conversation