BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hello All,

I want to add new values to the variables in SAS Dataset. I used the code:-

Assume that the SAS dataset in the location "C:SAS" so that when I open it it gets opened in the Tmp file. The SAS dataset is "star" and I used the code:-

proc contents data=Tmp1.star;
run;

There are 6 variables in this dataste each of length 8, say , A,B,C,D,E,F. If I want to add 3 values to all 6 variables then what code will add the values to the SAS Dataset?

Kindly guide.
Kriti
3 REPLIES 3
chang_y_chung_hotmail_com
Obsidian | Level 7
"Adding new values" is a bit fuzzy. You can either "replace values of a variable" like:
[pre]
/* append " Jr." at the end of name */
data juniors;
length name $30.;
set sashelp.class;
name = catx(" ", name, "Jr.");
run;
/* check */
proc print data=juniors;
var name;
run;
/* on lst
Obs name
1 Alfred Jr.
2 Alice Jr.
3 Barbara Jr.
4 Carol Jr.
5 Henry Jr.
6 James Jr.
7 Jane Jr.
8 Janet Jr.
9 Jeffrey Jr.
10 John Jr.
11 Joyce Jr.
12 Judy Jr.
13 Louise Jr.
14 Mary Jr.
15 Philip Jr.
16 Robert Jr.
17 Ronald Jr.
18 Thomas Jr.
19 William Jr.
*/
[/pre]

Or you can "append new observations" to a data set, like:
[pre]
/* data set with two observations */
data names;
length name $8;
name = "Albert"; output;
name = "Becky"; output;
run;
/* append one more observation */
data anotherName;
length name $8;
name = "Cathy"; output;
run;
proc append base=names data=anotherName;
run;

/* check */
proc print data=names;
run;
/* on lst
Obs name
1 Albert
2 Becky
3 Cathy
*/
[/pre]
deleted_user
Not applicable
Hello,

I first exported the SAS dataset to Excel using the code:-

Libname sc “C:\SAS”;
PROC EXPORT DATA= sc.newdata
OUTFILE= "c:\CWA\newdata.xls"
DBMS=EXCEL2000 REPLACE;
RUN;


There are 6 variables (A,B,C,D,E,F) and the length of is six. Although I could manually add new rows to this Excel sheet "newdata.xls", but is there a code that I could use in SAS that will add rows to this Excel sheet.

Kindest regards,
Kriti
Ksharp
Super User
yes. You can do it.
Using DDE skill of SAS or 'filename' +'put' statement.
In the previous post, '@data _null_;' and 'Peter.C' success to copy contents from one excel file to another excel file.

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 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 830 views
  • 0 likes
  • 3 in conversation