BookmarkSubscribeRSS Feed
rohithverma
Obsidian | Level 7

Hi All,

Could we have same variable names two times in sas dataset.Please help me .

 

Eg: NAME SEX HEIGHT WEIGHT SEX

 

 

6 REPLIES 6
PaigeMiller
Diamond | Level 26

No, you can't do this. You could name the second occurrence as SEX2

--
Paige Miller
ed_sas_member
Meteorite | Level 14

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;

Capture d’écran 2020-04-20 à 17.26.28.png

 

 

Reeza
Super User

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;
ballardw
Super User

@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.

PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
Kurt_Bremser
Super User

@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.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1183 views
  • 2 likes
  • 6 in conversation