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!
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?
As Jagadishkatam 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;
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 |
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.
I figured it . The upper case 'I' was the lower case 'l' (L). I dropped the variable and it works fine. Thanks!
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.