After trying many examples of solutions I have found here on SAS communities I still can't get this to work. The incoming SSN variable is $12 with a format and informat. What we want is $11 with no format or informat. I thought that by specifying the LENGTH statement before the SET statement that it would solve the problem but I am still getting the warning.
DATA WORK.new;
LENGTH SSN $11;
RETAIN SSN VisitDt HtIn WtLb SBP DBP;
SET dataset;
LABEL SSN = 'Social Security Number'
VisitDt = 'Visit Date'
HtIn = 'Height (In)'
WtLb = 'Weight (Lb)'
SBP = 'Systolic BP (mmHg)'
DBP = 'Diastolic BP (mmHg)';
FORMAT SSN SBP DBP;
INFORMAT SSN;
KEEP SSN VisitDt HtIn WtLb SBP DBP;
RUN;
Thank you for your help!
As soon as you forcibly shorten an existing variable, you will get the WARNING, and that is as it should be.
The proper way to deal with this is to fix your import process(es), so that the datasets are created with consistent variable attributes across the board.
If you do not have it already, set up a catalog that describes the attributes, and use that for writing the import programs.
Reducing the length of the variable ssn has been discussed recently in epic-length, so please use the search function to find it. Best way to solve such problem is fixing the code creating the variable with the wrong length, not reducing it afterwards.
As soon as you forcibly shorten an existing variable, you will get the WARNING, and that is as it should be.
The proper way to deal with this is to fix your import process(es), so that the datasets are created with consistent variable attributes across the board.
If you do not have it already, set up a catalog that describes the attributes, and use that for writing the import programs.
Hi Kurt,
Thank you for your solution. I hadn't thought of that. Unfortunately for this issue we are supposed to find a way to code the change in variable length. Also, this is an excel file import and because of my system configuration I have to use PROC IMPORT. Can you specify variable lengths when importing that way? What finally worked for me was this (this is not the whole datastep - just the part that addresses the variable length):
DATA WORK.new;
LENGTH SSN $11;
RETAIN SSN VisitDt HtIn WtLb SBP DBP;
SET dataset (RENAME = (SSN = SSN_temp));
SSN= SSN_temp;
Thanks again!
A
To get full control of the import process (the "E" in "ETL"), load the file in Excel and save the sheet as a .csv file. That file can be read with a data step, where you set all attributes consistently.
Otherwise, your correction step is the best you can do.
Hi!
I was having the same issue. Heres what worked for me.
I had to strip the SSN in the IA data to not have any spaces before or after which I did with the following code. This made it 11 characters long
DATA WORK.data;
LENGTH SSN $11;
SET import.vit (RENAME=(SSN=SSN2));
KEEP SSN VisitDt HtIn WtLb SBP DBP;
HtIn=ROUND(.393701*HtCm, 1);
WtLb=ROUND(2.20462*WtKg, 1);
SSN=STRIP(SSN2);
FORMAT VisitDt DATE9.;
RUN;
Then to get rid of the formats and in-formats on the combined data I used the following code
DATA tabs.vit;
SET tabs.vit;
FORMAT SSN HtIn WtLb SBP DBP;
INFORMAT SSN VisitDt HtIn WtLb SBP DBP;
RUN;
Hope this helps!
To only change formats and informats, it is better to use PROC DATASETS, as that only rewrites the first dataset page, and not the whole dataset.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.