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;

 

 

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1516 views
  • 0 likes
  • 5 in conversation