Format for float using Input

Accepted Solution Solved
Reply
Valued Guide
Posts: 619
Accepted Solution

Format for float using Input

Why does this produce .03 instead of 3? 

proc sql;
create table test (
graduation_period varchar(6),
cohort varchar(6)
);

insert into test (graduation_period, cohort) values ("201120", "200810");
quit;
data outputTable; set test;
time_to_graduation = input(substr(graduation_period, 1,4), 6.2) - input(substr(cohort, 1,4), 6.2);
run;

 

I'm trying to run this after.

 

proc sql;
create table test (
graduation_period varchar(6),
cohort varchar(6)
);

insert into test (graduation_period, cohort) values ("201120", "200810");
quit;
data outputTable; set test;
time_to_graduation = input(substr(graduation_period, 1,4), 6.2) - input(substr(cohort, 1,4), 6.2);

if(time_to_graduation * 100 - input(graduation_period, 8.) - input(cohort, 8.) = 90) then time_to_graduation = time_to_graduation + .33;
if(time_to_graduation * 100 - input(graduation_period, 8.) - input(cohort, 8.) = 20) then time_to_graduation = time_to_graduation + .33;
if(time_to_graduation * 100 - input(graduation_period, 8.) - input(cohort, 8.) = 80) then time_to_graduation = time_to_graduation + .66;
if(time_to_graduation * 100 - input(graduation_period, 8.) - input(cohort, 8.) = 10) then time_to_graduation = time_to_graduation + .66;
run;

Accepted Solutions
Solution
‎05-30-2018 05:02 PM
Valued Guide
Posts: 619

Re: Format for float using Input

Posted in reply to DavidPhillips2

This worked

 

 

time_to_graduation = input(graduation_period, 4.) - input(cohort, 4.);
if(input(graduation_period, 6.) - input(cohort, 6.) - time_to_graduation * 100) = 10 then do;
time_to_graduation = time_to_graduation + .66;
end;

View solution in original post


All Replies
PROC Star
Posts: 8,165

Re: Format for float using Input

Posted in reply to DavidPhillips2

You're forcing the last two digits to be a fraction. Why not just use:

data outputTable; set test;
  time_to_graduation = input(substr(graduation_period, 1,4), 4.) - input(substr(cohort, 1,4), 4.);
run;

Art, CEO, AnalystFinder.com

 

Valued Guide
Posts: 619

Re: Format for float using Input

[ Edited ]

That works for that line but,  I need to add the value from that to the fraction on the next part.

Super User
Posts: 6,785

Re: Format for float using Input

That's the right issue.  And as long as you are doing that, you don't need SUBSTR:

 

time_to_graduation = input(graduation_period, 4.) - input(cohort, 4.);

Valued Guide
Posts: 619

Re: Format for float using Input

Posted in reply to Astounding

How do I convert it so the next line will work with it?

 

 

time_to_graduation = input(graduation_period, 4.) - input(cohort, 4.);
if(time_to_graduation * 100 - input(graduation_period, 8.) - input(cohort, 8.) = 90) then time_to_graduation = time_to_graduation + .33;

Solution
‎05-30-2018 05:02 PM
Valued Guide
Posts: 619

Re: Format for float using Input

Posted in reply to DavidPhillips2

This worked

 

 

time_to_graduation = input(graduation_period, 4.) - input(cohort, 4.);
if(input(graduation_period, 6.) - input(cohort, 6.) - time_to_graduation * 100) = 10 then do;
time_to_graduation = time_to_graduation + .66;
end;

Super User
Posts: 13,583

Re: Format for float using Input

Posted in reply to DavidPhillips2

You might provide exactly what you are attempting to do. Since this looks like date manipulation and comparisons then it may be that intck and/or intnx with some actual date values instead with offsets may be of use. Though we would need some explanation of what 201120 and 200810 actually represent. The first four digits look like years but the 20 in 201120 is not intuitively obvious.

 


@DavidPhillips2 wrote:

How do I convert it so the next line will work with it?

 

 

time_to_graduation = input(graduation_period, 4.) - input(cohort, 4.);
if(time_to_graduation * 100 - input(graduation_period, 8.) - input(cohort, 8.) = 90) then time_to_graduation = time_to_graduation + .33;


The 8 format isn't going to do will reading 6 characters...

Your calculation has a number of magic numbers. What is the purpose of the 100 and the .33?

As a minimum I think we need at least 2 if not a couple more worked examples showing the expected result.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 111 views
  • 0 likes
  • 4 in conversation