Hello! I am new to sas! How could I accomplish this?
Someone wants to join the Data.master file to another table using student ID. However, the studentID column in the table to be joined is a character variable. Convert the numeric student ID variable in the master file to be a character variable. Write this new file to the work library.
Data.master screenshot:
Thanks!
Using a SAS data step:
data want;
set data.master(rename=(studentID=studentIDNum));
studentID=put(studentIDNum,z5.);
drop studentIDNum;
run;
This will work:
proc sql ;
create table converted as select input (studentid, best.) as studentid, * from have ;
quit ;
However, you will get the warning:
WARNING: Variable studentid already exists on file WORK.CONVERTED.
This will work, too - but you will not get the warning:
proc sql ;
create table converted (drop=_id) as select input (_id, best.) as studentid, * from have (rename=studentid=_id) ;
quit ;
Kind regards
Paul D.
I like the smart REnaming upfront and make the select * work.
Tell you what, up until this point I have been so lazy and relying on FEEDBACK NOEXEC options to copy paste the expanded SELECT clause written to the LOG. Hmm, i will keep in mind to copy the new idea.
proc sql feedback noexec;
select *
from sashelp.class;
quit;
Using a SAS data step:
data want;
set data.master(rename=(studentID=studentIDNum));
studentID=put(studentIDNum,z5.);
drop studentIDNum;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.