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: Call for Content

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!

Submit your idea!

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