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;
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;
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
That works for that line but, I need to add the value from that to the fraction on the next part.
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.);
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;
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;
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.
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.
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.