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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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