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.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 6 replies
  • 674 views
  • 2 likes
  • 6 in conversation