- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
That works for that line but, I need to add the value from that to the fraction on the next part.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.);
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.