BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
cneed
Obsidian | Level 7

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.PNG

 

Data.master screenshot:

Data.master Datafile.PNG

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

Using a SAS data step:

data want;
  set data.master(rename=(studentID=studentIDNum));
  studentID=put(studentIDNum,z5.);
  drop studentIDNum;
run;

View solution in original post

3 REPLIES 3
hashman
Ammonite | Level 13

@cneed:

 

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.

novinosrin
Tourmaline | Level 20

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;
Patrick
Opal | Level 21

Using a SAS data step:

data want;
  set data.master(rename=(studentID=studentIDNum));
  studentID=put(studentIDNum,z5.);
  drop studentIDNum;
run;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 3 replies
  • 601 views
  • 1 like
  • 4 in conversation