SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
ywliang960
Calcite | Level 5

data work.titaniccsv;
         length pclass $1 survived $1
         name $82 sex $8 age $2
         sibsp $1 parch $1
         ticket $20 fare $10
         cabin $10 embarked $1
         boat $5 body $4
         home_dest $70;

infile '/home/ywliang960/Titanic/titanic3.csv' firstobs=2 dsd;
input pclass survived name $ sex $ age sibsp
         parch ticket $ fare cabin $ embarked $
         boat $ body home_dest $;
Age= round(age);


run;

 

 

I'm able to round off every decimals EXCEPT for numbers like 0.92, 0.72. Those numbers rounded off to 0 instead of 1. Any ideas to solve it?


undefined
2 REPLIES 2
Reeza
Super User

You've specified Age as a character variable ($2) but are then trying to apply numeric functions to the variable. Read it in as a number instead and you should be fine. 

 

You may may want to revise your length statement for all your numeric variables and remove the extra $ before the length. 

PeterClemmensen
Tourmaline | Level 20

Read in Age as a numeric variable and still use the round function like

 

data mydata;
   input Name $ Age;
   datalines;
Bill 12.4
Carlos 35.7
Monique 0.12
Peter 0.78
;

data roundedData;
   set mydata;
   IntAge = Round(Age);
run;

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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