- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I have a dataset that I transposed, however, I am trying to rename an id variable (ptid) before I merge this dataset with another one. I don't get an error message but after running the rename statement, it does not change the variable in the dataset (and when I run a proc contents to see the variable name, it says the variable (and label) are ptid). Any help would be greatly appreciated!
This is the code I ran to transpose the dataset (would this have cause any issues with my renaming):
data heartcount;
set newresults;
array diag (24) diag1-diag24;
heart=0;
do _n_=1 to dim(diag);
if diag{_n_}in: ("250","E11","E10") then heart+1;
end;
run;
trying to rename variable and sort dataset before I merge:
proc sort data = heartcount out=ribdata (rename= ptid=idnum);
by ptid;
run;
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You don't get an error message, but the code you show absolutely will produce an error message.
The proper syntax is
proc sort data = ex.spine out=spine2 (rename=(ptid=idnum));
by ptid;
run;
Note the extra parentheses.
If that doesn't work for you, please show us the entire log for these steps (code as seen in the log, plus any errors or warnings, do not chop out any part of the log for these steps).
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi Paige, this is the log I get for when I try the correct syntax you provided:
364 proc sort data = heartcount out= spine2 (rename=(ptid=idnum));
365 by ptid;
366 run;
NOTE: Input data set is already sorted; it has been copied to the output data set.
NOTE: There were 32844 observations read from the data set WORK.HEARTCOUNT.
NOTE: The data set WORK.SPINE2 has 32844 observations and 28 variables.
NOTE: PROCEDURE SORT used (Total process time):
real time 0.02 seconds
cpu time 0.01 seconds
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
If you read the log, it explains why no sorting was done, and why the variable is not renamed.
NOTE: Input data set is already sorted; it has been copied to the output data set.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You'll have to rename it in whatever the next step is.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@PaigeMiller @Tom You can definitely rename within a sort and you do not need brackets around the rename if it's only one set of variables so that's not the issue with OP's code, something else is the issue. This code works perfectly fine and the class2 data set has the renamed variable as indicated.
data class;
set sashelp.class;
run;
proc sort data=class;
by sex age;
run;
proc sort data=class out=class2(rename=name=ID);
by sex age;
run;
proc contents data=class2;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Are you sure you aren't looking at the LABEL instead of the NAME of the variable.
It definitely works for me, even when the data is sorted already.
2897 proc sort data=sashelp.class out=class ; by sex; run; NOTE: There were 19 observations read from the data set SASHELP.CLASS. NOTE: The data set WORK.CLASS has 19 observations and 5 variables. NOTE: PROCEDURE SORT used (Total process time): real time 0.04 seconds cpu time 0.01 seconds 2898 proc sort data=class(rename=(name=name2)) out=class2; by sex; run; NOTE: Input data set is already sorted; it has been copied to the output data set. NOTE: There were 19 observations read from the data set WORK.CLASS. NOTE: The data set WORK.CLASS2 has 19 observations and 5 variables. NOTE: PROCEDURE SORT used (Total process time): real time 0.00 seconds cpu time 0.01 seconds 2899 proc compare data=class compare=class2; run;
Results
Data Set Summary Dataset Created Modified NVar NObs Label WORK.CLASS 23MAR20:14:56:21 23MAR20:14:56:21 5 19 Student Data WORK.CLASS2 23MAR20:14:56:21 23MAR20:14:56:21 5 19 Student Data Variables Summary Number of Variables in Common: 4. Number of Variables in WORK.CLASS but not in WORK.CLASS2: 1. Number of Variables in WORK.CLASS2 but not in WORK.CLASS: 1. SAS 9.4 on WINDOWS 13:12 Thursday, March 19, 2020 44 The COMPARE Procedure Comparison of WORK.CLASS with WORK.CLASS2 (Method=EXACT) Observation Summary Observation Base Compare First Obs 1 1 Last Obs 19 19 Number of Observations in Common: 19. Total Number of Observations Read from WORK.CLASS: 19. Total Number of Observations Read from WORK.CLASS2: 19. Number of Observations with Some Compared Variables Unequal: 0. Number of Observations with All Compared Variables Equal: 19. NOTE: No unequal values were found. All values compared are exactly equal.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Yes you can rename it during PROC TRANSPOSE, or you can rename in the step where you do the merge.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Proc transpose data=shortdiag
out=newresults2 (rename=(hdghraencwid=hraencwid))
prefix=diag;
by hdgHraEncWid;
var diagnosis;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I really doubt that RENAME= option is not working for you. You are either looking at the wrong dataset or not looking at the NAME of the variable.
Please show the proc contents for the dataset newresults2.