BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
dr2014
Quartz | Level 8

Hi,

I am working with 3 sas datasets each of which have 2 identically named variables e.g txtcmmnt. One of them has a label and the other doesn't. When I use a keep option it only shows one variable but a proc contents or a veiw of the datasets it shows the 2 variables. I need to stack the 3 datasets into a final sas dataset . I would like to delete the variable with no label. How should I do it? Any suggestions will be helpful.

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16
I am not sure if we could have 2 variables with the same name in the same dataset. Could you please check again, i think they will be some difference in names of those 2 variables.
Thanks,
Jag

View solution in original post

7 REPLIES 7
Jagadishkatam
Amethyst | Level 16
I am not sure if we could have 2 variables with the same name in the same dataset. Could you please check again, i think they will be some difference in names of those 2 variables.
Thanks,
Jag
dr2014
Quartz | Level 8

I thought the same so I did a proc content to carefully check the spellings:

This is an example of what shows up in the proc contents:

Variable     Type    Length    Format    Informat    Label

Txtcmmnt   Char    1754                                       1. Is there anything you would like to add?

Txtcmmnt   Char    146                       $146    

Its the second one with no label that I would like to delete.

Any suggestions?

RW9
Diamond | Level 26 RW9
Diamond | Level 26

As  has metioned, you cannot have two separate columns, which have the same name in one dataset.  Its not possible within SAS.  Can you provide example data?

If you stack data, then it should keep the properties of the first dataset:

data tmp;
  label a="Hello";
  a="Abc";
run;
data tmp2;
  a="Def";
run;
data final;
  set tmp tmp2;
run;

One way you could force it is to use SQL, with union all, and specify the labels in the first select:

proc sql;  
  create table FINAL as
  select  VARA label="xyz"
  from    TMP
  union all
  select * 
  from    TMP2
  union all...
quit;
dr2014
Quartz | Level 8

I agree with both of you. I checked the spellings of the variables . There is uppercase 'I' and looked to see if it is a '1' and it is not. The thing is when I try to stack the datasets , inspite of getting the lengths uniform on the variable txtcmmnt it gives me a warning message:

WARNING: Multiple lengths were specified for the variable txtCmmnt by input data set(s). This can cause

         truncation of data

The new lengths get applied only to the variable with the label. Have you come across something like this? Also, @RW9, the dataset looks like this

ID txtcmmnt txtcmmnt
1 eerrr  
2 rrrrr  
3 ttttt r
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Try opening the properties of the two datasets.  What you are showing below doesn't really show anything.  I suspect the two variables have the same LABEL, but the variable NAME is different.  Run a proc contents of each one, or right click on the file and select properties.

dr2014
Quartz | Level 8

I figured it . The upper case 'I' was the lower case 'l' (L). I dropped the variable and it works fine. Thanks!

Doc_Duke
Rhodochrosite | Level 12
dr2014: Your question would have been answered much quicker if you had included the ACTUAL variable names. There is no 'l' or '1' in the examples.

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
  • 7 replies
  • 1070 views
  • 2 likes
  • 4 in conversation