DATA Step, Macro, Functions and more

Variable EmpId has been defined as both character and numeric.

Reply
Occasional Contributor
Posts: 5

Variable EmpId has been defined as both character and numeric.

 

this is my code

 

 

options pagesize=60 linesize=80 pageno=1 nodate;

data new_accounting (rename = (TempVar =EmpId) drop= EmpId);
	set accounting;
	TempVar = put(EmpId,$9.);
run;

proc datasets library=work;
	contents data = new_accounting;
run;


data dept1_4;
	set sales CustomerSupport Security new_accounting ;
run;
proc print data=dept1_4;
title 'Employees in Sales, Customer Support, Security,';
title2 'and Accounting Departments';
run;

 

 

data shipping;
	input EmpId 1-9 EmpName $ 11-29 Gender $ 30 @32 HireDate date9. @42 Salary;
	format HireDate date7.
		   Salary comma6.;
	datalines;
688774609 Carlton, Susan     F 28jan1995 29200
922448328 Hoffmann, Gerald   M 12oct1997 27600
544909752 DePuis, David      M 23aug1994 32900
745609821 Hahn, Kenneth      M 23aug1994 33300
634774295 Landau, Jennifer   F 30apr1996 32900
;
run;

proc print data = shipping;
	title ' Shipping details';
run;

data dept5_1;
	set shipping new_accounting Security sales CustomerSupport;
run;

proc print data = dept5_1;
	title ' Employees in Shipping, Accounting, Security,';
	title2 ' Customer Support, and Sales Departments';
run;
203        
 204        data dept5_1;
 205        set shipping new_accounting Security sales CustomerSupport;
 ERROR: Variable EmpId has been defined as both character and numeric.
 206        run;
 

 

Error: 

 

 

 

 NOTE: PROCEDURE DATASETS used (Total process time):
       real time           0.08 seconds
       cpu time            0.08 seconds
       
 176        data dept1_4;
 
 177        set sales CustomerSupport Security new_accounting ;
 ERROR: Variable EmpId has been defined as both character and numeric.
 178        run;

 

 

Super User
Posts: 6,963

Re: Variable EmpId has been defined as both character and numeric.

With this:

data new_accounting (rename = (TempVar =EmpId) drop= EmpId);
	set accounting;
	TempVar = put(EmpId,$9.);

you have specifically created tempvar as character (because of using a character format in the put statement) and then replaced empid with the newly defined character variable.

Here:

data shipping;
	input EmpId 1-9 EmpName $ 11-29 Gender $ 30 @32 HireDate date9. @42 Salary;

you do not specify empid to be character, therefore SAS creates it as numeric.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Ask a Question
Discussion stats
  • 1 reply
  • 307 views
  • 0 likes
  • 2 in conversation