BookmarkSubscribeRSS Feed
Bogusval
Fluorite | Level 6

Just wondering if there is a more efficient way to charge a var from char to num.   Often I import dataset and find out in a merge that the varible isn’t the same type.  This is how I do it

 

Data hello;

     Set Bye;

     NumKite = input(kite, 8.);

     Drop kite;

     Rename NumKite = Kite;

run;

 

Is there a better way rather then the drop and rename?

 

thank you for your help

4 REPLIES 4
SASKiwi
PROC Star

By far the best approach is to import it into the correct data type to begin with and not convert it at all. I bet you are importing from Excel which has a mind of its own when deciding in what format it will deliver data. One way to enforce correct data types is to import from CSV files and not Excel. Is this a possibility for you?

Bogusval
Fluorite | Level 6
Usually the files I get are in excel and just for a one time use. I often have to merge the file with another file to analyze it. I could save it as a .csv but don't want to go to all try trouble of defining all the variables in an infile statement. I like that sas can guess on an excel file but just was thinking there might be a easier way to change the type.

Thanks
SASKiwi
PROC Star

You don't have to define all your variables to import a CSV file. You can use PROC IMPORT with DBMS = CSV similar to Excel. Using the GUESSINGROWS option as well will probably get you a better result than with Excel.

Tom
Super User Tom
Super User

Not really.

If you are doing your "merge" using SQL then you can just do the conversion there.

proc sql ;
create table want as
select * 
from a , b
where a.kite = input(b.kite,32.)
;
quit;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 850 views
  • 0 likes
  • 3 in conversation