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

Hello Community,

I am just following up with my question in Check if the variable is numeric then convert to Char . 

Thank you all for your valuable replies.

 

In my case I am reading from different XML files, So I dont know if it is numeric or character datatype originally. So ideally what I need to do is something like

%if (%sysfunc(vartype(xyz.myVar)) = N) %then  %do;
put(xyz.myVar,$5.);
%end

proc sql;
  create table abc as 
  select myvar
  from xyz;
  quit;

 

In this way no matter what the data type is , I can always read a character.

 

Please help 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

I think the CAT solution proposed would work, did that not work for your for some reason?

 

option missing='';
data class;
set sashelp.class;
if name in ('Alfred' 'Jane') then age=.;
run;


proc sql;
create table want as
select name, catt(age) as age, weight, height
from class;
quit;

View solution in original post

4 REPLIES 4
Reeza
Super User

I think the CAT solution proposed would work, did that not work for your for some reason?

 

option missing='';
data class;
set sashelp.class;
if name in ('Alfred' 'Jane') then age=.;
run;


proc sql;
create table want as
select name, catt(age) as age, weight, height
from class;
quit;

jjames1
Fluorite | Level 6

Thank you for the quick reply.

Although this one runs and changes the data type ; the value is missing

Reeza
Super User

@jjames1 wrote:

Thank you for the quick reply.

Although this one runs and changes the data type ; the value is missing


I don't understand what that means.

jjames1
Fluorite | Level 6

Hello Reeza,

It was an error from my side.

This way of conversion worked.

Thank you so much 🙂

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!

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