Help using Base SAS procedures

Adding new varibale

Reply
Regular Contributor
Posts: 229

Adding new varibale

i have a data set
data i;
input x;
cards;
7
8
9
10
11
run;

now i want a new variable to be addeed the variable name should be employ and the observations should be employee1,employee2,employee3,employee4,employee5.
Super Contributor
Posts: 259

Re: Adding new varibale

It is not necessary to open a second thread for the same topic.
http://support.sas.com/forums/thread.jspa?threadID=3901&tstart=15

Does the number in "employee1" depend on
a) the number of the current obersavtion,
b) any other variable in that oberservation?

One possible solution:
[pre]
data work.extended;
set i;
length employ $ 15; /* defines a character-variable, with enough space for 15 chars */
employ = cat('employee', _n_); /* _n_ = the number of the current obersvation */
run;
[/pre]
Super Contributor
Super Contributor
Posts: 3,174

Re: Adding new varibale

Share info about what you would like the end result to look like - multiple observations and variables, multiple variables and one observation. Do you want the "employ" order to be sorted, based on some component of a SAS variable or just based on the raw input occurrences?

Consider using PROC TRANSPOSE if you want to have one observation in total and a unique SAS variable employee1 through employee## for each unique value.

Scott Barry
SBBWorks, Inc.
Ask a Question
Discussion stats
  • 2 replies
  • 104 views
  • 0 likes
  • 3 in conversation