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

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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.

View solution in original post

6 REPLIES 6
andreas_lds
Jade | Level 19

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.

Kurt_Bremser
Super User

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.

txim33
Calcite | Level 5

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

Kurt_Bremser
Super User

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.

hspears
Calcite | Level 5

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! 

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 6 replies
  • 16030 views
  • 0 likes
  • 4 in conversation