Hi All,
Could we have same variable names two times in sas dataset.Please help me .
Eg: NAME SEX HEIGHT WEIGHT SEX
No, you can't do this. You could name the second occurrence as SEX2
Hi @rohithverma
That's not possible at all in a dataset.
However, you can have that in a report for display:
proc sql;
select name, sex, height, weight, sex from sashelp.class;
run;
Another option is to use a variable label.
proc print data=sashelp.class labels noobs;
var name age sex weight height;
label name = 'Name' age = 'Age' sex = 'Sex' weight = 'Name' ;
run;
@rohithverma wrote:
Hi All,
Could we have same variable names two times in sas dataset.Please help me .
Eg: NAME SEX HEIGHT WEIGHT SEX
Why? Please describe what you would use this for. Possibly in quite a bit of detail.
At first glance this sounds like a "make SAS data look like Excel" question. Which is in many case not a good idea for analysis. But the final output in a Report may be made to look somewhat like that.
I spend entirely too much time cleaning up data generated in spreadsheets that has the "same variable" multiple times and NEVER does the variable actually mean the exact same thing. One typical example is "Total". Where in one column Total is "Total number of Students" in another column "Total number of students enrolled in Class X" (repeat for class Y, Z, etc). So the "Total" is not the same value and hence should be a different variable.
Yes, @rohithverma , if you provide some context for you question, you will likely get more useful answers than all the guessing in the dark that I and others have done.
@rohithverma wrote:
Hi All,
Could we have same variable names two times in sas dataset.Please help me .
Eg: NAME SEX HEIGHT WEIGHT SEX
No. You can have the same label, though.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.