DATA Step, Macro, Functions and more

rename values on tables

Reply
N/A
Posts: 0

rename values on tables

hi
I'm completely new to sas and to this community then feel free to remove my post if it isn't to his place.

I know how to rename the variables, but what about renaming the values from a table ? I mean, if we have :

V1 V2
o1 x11 x12
o2 x21 x22

where o1, o2 are the number of the observations and V1, V2 the variables.

Is it possible to rename xij ? How we can proceed ?

Thanks

Message was edited by: babaorumi Message was edited by: babaorumi
Respected Advisor
Posts: 3,889

Re: rename values on tables

Hi babaorumi

You might think of a SAS dataset as if it were a Excel spreadsheet.
The variable names are the column names (and actually they are not that easy to rename) - an observation (record) is a line in the spreadsheet. A cell contains the value of a distinct variable ( a "column") at a specific point of iterating through the dataset.
That's what a datastep mainly does. It iterates through the "lines of the spreadsheet", from top to bottom, one line at a time between the "data" statement and the "run" statement.

So what you're asking for - changing the value of a variable (a cell value) - is the most basic thing you can do in SAS.

Let's assume the following:
you have:
data have;
/* write ten observations (records) to table have with one column (variable) "myvar" */
do myvar=1 to 10;
output; end;
run;

data recode;
set have;
if myvar=5 then myvar=999;
run;
proc print data=myvar;
run;


HTH
Patrick
N/A
Posts: 0

Re: rename values on tables

Thank you for a so fast and complete reply.
Gonna try monday, because I unfortunately haven't SAS at home.
Baba
N/A
Posts: 0

Re: rename values on tables

xij could be regard as the value of the variable, it is string type, so, to some extent, revise it is just as change the value of a variable , think about if xij is a numerical value, how would you revise it, the technique is much the same, but maybe you have to use some function and special operator , since you may have to combine the string.
SAS Super FREQ
Posts: 8,743

Re: rename values on tables

Hi:
It seems to me that you want to treat the entire dataset as though it is an array, like this:
[pre]
V1 V2
o1 x11 x12
o2 x21 x22
[/pre]
as though x(i,j) is a value that you can derive positionally from the "row" order in the dataset and the column order.

However, if the data were sorted in DESCENDING order by V1, then your dataset would look like this:
[pre]
V1 V2
o1 x21 x22
o2 x11 x12
[/pre]

where the "row" order no longer would correspond to the x(i,j). The SAS observation numbers or row numbers are not "fixed"...they do not stay in the file. They only appear on reports like PROC PRINT and PROC UNIVARIATE in order to help you locate rows. The observation number can and will change depending on the sort order of the file, whether you have deleted any observations, etc.

Just something else to think about.

cynthia
Ask a Question
Discussion stats
  • 4 replies
  • 1803 views
  • 0 likes
  • 3 in conversation