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

When I run this code, SAS is automatically assigning formats and informats to all of my data when I only want a format on my date variable. Am I accidentally creating these formats and informats or I am missing something? Is there any way that I can get SAS to stop creating these Formats and Informats? I have copied the formats that I keep getting below.

*	Creating data for Iowa   *;
DATA	WORK.Vitals_IA ;
	HtIn = HtCm * 2.54;
	WtLb = WtKg * .454;
	DROP HtCm WtKg;
	SET	HypImpt.Vit_IA (RENAME = (SSN = FedData));
	SSN = PUT(FedData, 11.);
	DROP FedData;
	RUN;

*	Creating data for Mississippi   *;
DATA	WORK.Vitals_MS (RENAME = (VisitDate = VisitDt Height = HtIn Weight = WtLb));
	SET	HypImpt.Mississippi_VS;

	RUN;

*	Creating data for Utah   *;
DATA	WORK.Vitals_UT;
	LENGTH SSN $11.
		   pt1 $3.
		   pt2 $2.
		   pt3 $4.;
	SET HypImpt.utah_vitals: (RENAME = (ApptDate = VisitDt));
	IDs = STRIP(SSN);
		pt1 = substr(IDs,1,3);
		pt2 = substr(IDs,4,2);
		pt3 = substr(IDs,6,4);
	SSN = CATX('-', pt1, pt2, pt3);
	RUN;

PROC TRANSPOSE	
		DATA = WORK.Vitals_UT
		OUT = WORK.Vitals_UT2 (DROP = _NAME_ _LABEL_ RENAME = (Col1 = HtIn Col2 = WtLb Col3 = SBP Col4 = DBP));
	VAR Value;
	BY VisitDt SSN;
	RUN;
	

*	Creating Combined Data Set   *;


DATA	HypTabs.Vitals (LABEL = Vital Signs);

	ATTRIB SSN LABEL= 'Social Security Number' LENGTH = $11.
		   VisitDt LABEL= 'Visit Date' LENGTH = 8. FORMAT = DATE9.
		   HtIn LABEL = 'Height (In)' LENGTH = 8.
		   WtLb LABEL= 'Weight (Lb)' LENGTH = 8.
		   SBP LABEL= 'Systolic BP (mmHg)' LENGTH = 8.
		   DBP LABEL= 'Diastolic BP (mmHg)' LENGTH = 8.;
	KEEP SSN VisitDt HtIn WtLb SBP DBP;

	SET	WORK.Vitals_IA
		WORK.Vitals_MS
		WORK.Vitals_UT2;

	

	RUN;


PROC SORT DATA= HypTabs.Vitals;
	BY SSN VisitDt;
RUN;

PROC CONTENTS DATA= HypTabs.Vitals VARNUM;
RUN;

PROC PRINT DATA= HypTabs.Vitals (obs=1);
RUN;

 

 

 

 

Variables in Creation Order# Variable Type Len Format Informat Label123456

SSNChar11$9.$9.Social Security Number
VisitDtNum8DATE9. Visit Date
HtInNum8BEST. Height (In)
WtLbNum8BEST. Weight (Lb)
SBPNum8BEST12. Systolic BP (mmHg)
DBPNum8BEST12. Diastolic BP (mmHg)
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

That is the step where you are reading in an unknown number of inputs because you are using the colon wildcard in the list of dataset on the SET statement. So you need to check all of them to see whether any of them have a format attached to the variables you are interested in.  When you combine multiple datasets SAS will pick the first non missing format for each variable.  So you just cannot check the first dataset because if the variable has no format attached in the first dataset, but does in the second dataset then the result will be to use the format that the variable had in the second dataset.

 

To remove the formats just add a format statement that lists variable, but has no format specification, to your data step.

format visitdt date9. ssn HtIn WtLb SBP DBP ;

View solution in original post

4 REPLIES 4
Tom
Super User Tom
Super User

What formats are attached to those variables in the source datasets?

HypImpt.Vit_IA
HypImpt.Mississippi_VS
HypImpt.utah_vitals:
walkerel
Calcite | Level 5

None. Before I start manipulating anything, there are no formats or informats attached to the data.

walkerel
Calcite | Level 5
It seems as though the formats are all stemming from when I create my vitals_ut data from what I am seeing when I run the steps individually.
Tom
Super User Tom
Super User

That is the step where you are reading in an unknown number of inputs because you are using the colon wildcard in the list of dataset on the SET statement. So you need to check all of them to see whether any of them have a format attached to the variables you are interested in.  When you combine multiple datasets SAS will pick the first non missing format for each variable.  So you just cannot check the first dataset because if the variable has no format attached in the first dataset, but does in the second dataset then the result will be to use the format that the variable had in the second dataset.

 

To remove the formats just add a format statement that lists variable, but has no format specification, to your data step.

format visitdt date9. ssn HtIn WtLb SBP DBP ;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 4 replies
  • 545 views
  • 0 likes
  • 2 in conversation