BookmarkSubscribeRSS Feed
Rsadiq
Calcite | Level 5

Hello

 

I was trying to convert variables (MP_LASTNAME and MP_FIRSTNAME) to character variables in these statements? How would I go about this? I get an error that these variables are numeric and wasnt sure how besides using a put statements would do this for me.

 

from outlib.MCP_QUAL as a
          left join refdata.xwalk_careone_crm as b
           on UPCASE(COMPRESS(strip(a.PtFirst))) = UPCASE(COMPRESS(strip(b.MP_FIRSTNAME)))
               and UPCASE(COMPRESS(strip(a.PtLast))) = UPCASE(COMPRESS(strip(b.MP_LASTNAME)))
     ;quit;

 

Thank you

 

Rida

4 REPLIES 4
Jagadishkatam
Amethyst | Level 16
You would need to use the format and put function to convert the MP_FIRSTNAME and MP_LASTNAME to character. an example would be as below
UPCASE(COMPRESS(strip(a.PtFirst))) = UPCASE(COMPRESS(strip(put(b.MP_FIRSTNAME,fmt.))))
and UPCASE(COMPRESS(strip(a.PtLast))) = UPCASE(COMPRESS(strip(put(b.MP_LASTNAME,fmt.))))
Thanks,
Jag
Rsadiq1
Calcite | Level 5

I am trying this but its not working still giving me an error (put(a.PtFirst,format $15.))))

 

MPRINT(STEP2):   create table ALL_NPART as select distinct a.* ,b.MP_FIRSTNAME as _Fname format $15. ,b.MP_LASTNAME as _Lname
format $15. ,b.indv_id ,b.MP_MANAGEDPERSONID ,b.MP_BIRTHDATE as _DOB ,b.MP_zip as _zip from outlib.MCP_QUAL as a left join
refdata.xwalk_careone_crm as b on UPCASE(COMPRESS(strip(put(a.PtFirst,format $15.)))) = UPCASE(COMPRESS(strip(b.MP_FIRSTNAME))) and
UPCASE(COMPRESS(strip(put(a.PtLast,format $15.)))) = UPCASE(COMPRESS(strip(b.MP_LASTNAME))) ;
ERROR 22-322: Syntax error, expecting one of the following: a format name, ?. 

TomKari
Onyx | Level 15

You're close. You don't use the word "format" when using a format. Also, if you're converting a numeric variable to character, don't start the format name with a "$".

 

Here's an example of what you're trying to do:

 

proc sql;

create table TestTable as

select put(a.Age, 15.) as CharAge

from sashelp.class as a;

quit;

 

Tom

Astounding
PROC Star

Why can't you do this without conversion:

 

on a.PtFirst = b.MP_FIRSTNAME

and a.PtLast = b.MP_LASTNAME;

 

Are you certain that the variables were created properly in the first place?  It seems unusual for variables holding first and last name to be 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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 4 replies
  • 847 views
  • 0 likes
  • 5 in conversation