BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
4 REPLIES 4
Patrick
Opal | Level 21
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
deleted_user
Not applicable
Thank you for a so fast and complete reply.
Gonna try monday, because I unfortunately haven't SAS at home.
Baba
deleted_user
Not applicable
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.
Cynthia_sas
SAS Super FREQ
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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 4 replies
  • 9088 views
  • 0 likes
  • 3 in conversation