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;
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.
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!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: