BookmarkSubscribeRSS Feed
francisca
Calcite | Level 5

 

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;

 

 

1 REPLY 1
Kurt_Bremser
Super User

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.

sas-innovate-wordmark-2025-midnight.png

Register Today!

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.


Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1518 views
  • 0 likes
  • 2 in conversation