Help using Base SAS procedures

adding new values to the variables in SAS Dataset

Reply
N/A
Posts: 0

adding new values to the variables in SAS Dataset

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 "CSmiley FrustratedAS" 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
Regular Contributor
Posts: 241

Re: adding new values to the variables in SAS Dataset

Posted in reply to deleted_user
"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]
N/A
Posts: 0

Re: adding new values to the variables in SAS Dataset

Posted in reply to chang_y_chung_hotmail_com
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
Super User
Posts: 10,041

Re: adding new values to the variables in SAS Dataset

Posted in reply to deleted_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.
Ask a Question
Discussion stats
  • 3 replies
  • 135 views
  • 0 likes
  • 3 in conversation