SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
pkfamily
Obsidian | Level 7

I'm having a simple issue where my numbers are truncated after using the input function to convert characters to numeric. Perhaps I am missusing the input function or using the wrong informat? Code Below

 

 

data test;
length x $11 y $9;
input x y $;
datalines;
-117.088178 32.706038
;
run;

data test_t;set test;
x_t=input(x,11.6);
y_t=input(y,9.6);
run;

When I print the dataset I would expect:

 

                                                            x                   y                    x_t              y_t  

-117.08817832.706038-117.08817832.706038

 

But I get:

 

     x                   y                    x_t              y_t  
-117.08817832.706038-117.08832.7060
 

 

Any ideas? I'm currently using SAS 9.4 TS1M1

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

You are using the input function correctly. Add a format statement when you print the file. e.g.:

 

proc print data=test_t;
  format x_t y_t best32.;
run;

HTH,

Art, CEO, AnalystFinder.com

 

View solution in original post

3 REPLIES 3
art297
Opal | Level 21

You are using the input function correctly. Add a format statement when you print the file. e.g.:

 

proc print data=test_t;
  format x_t y_t best32.;
run;

HTH,

Art, CEO, AnalystFinder.com

 

pkfamily
Obsidian | Level 7

Thanks! So the data is stored correctly. It is just the default format for printing the data does not show those extra decimels. 

art297
Opal | Level 21

Correct. I would include the format statement while creating the file. Then, procs (like proc print) would always honor it.

 

Art, CEO, AnalystFinder.com

 

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 2664 views
  • 1 like
  • 2 in conversation