BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
avatar
Fluorite | Level 6

Hello!,

I am interested to calculate how many weeks to finish a job
The file has job assigned date and completed date . I have matched up with weeks table to find the week  the job was assigned and week it is completed.

For example,  if the job was assigned in week 16 and completed in week 21 then I would want to find all weeks it is in process, then I will count each week how many are in process and put that number in a graph showing progress.

I am looking to pull data from week 16 to 32.

Please help .

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
Diamond | Level 26

Hi:

  Since the ultimate request is for a graph, I wonder whether the second DATA step is needed. You could do everything in one DATA step program and then just use PROC SGPLOT for the graph.

Cynthia

data testdata;

  infile datalines dlm=',' dsd;

  input R_ID assign : date9. survey $ complete : date9.;

  wk_id = week(assign);

  assign_wk = week(assign);

  comp_wk = week(complete);

  num_wks= (comp_wk - assign_wk) + 1;

  do i = assign_wk to comp_wk by 1;

    plot_week = i;

    output;

  end;

  label plot_week = 'Week';

return;

datalines;

101, 03mar2014,  aaa, 18apr2014

110, 11apr2014,  aaa, 08may2014

202, 18feb2014,  aaa, 03apr2014

330, 12feb2014,  aaa, 12apr2014

404, 01mar2014,  aaa, 07apr2014

550, 13jan2014,  bbb, 06may2014

606, 24apr2014,  bbb, 12jun2014

770, 21mar2014,  bbb, 15may2014

808, 28feb2014,  bbb, 07may2014

990, 01may2014,  bbb, 12may2014

;

run;

    

ods pdf file='c:\temp\plot_week.pdf';

proc sgplot data=testdata;

  title 'See Number of Projects Each Week';

  vbar plot_week /datalabel group=plot_week;

run;

ods pdf close;

View solution in original post

3 REPLIES 3
Reeza
Super User

Virus scanning seems to be taking a long time these days, perhaps consider embedding the data in your question.

Without seeing anything, I'd expand your data so that you have a record for each week for each project. Then you can summarize and graph from that data more easily.

data have;

    input project $ week_start week_have;

cards;

A 23 41

B 21 27

C 34 45

D 1 14

;

run;

data expand;

    set have;

    do week=week_start to week_have;

    output;

    end;

run;

Cynthia_sas
Diamond | Level 26

Hi:

  Since the ultimate request is for a graph, I wonder whether the second DATA step is needed. You could do everything in one DATA step program and then just use PROC SGPLOT for the graph.

Cynthia

data testdata;

  infile datalines dlm=',' dsd;

  input R_ID assign : date9. survey $ complete : date9.;

  wk_id = week(assign);

  assign_wk = week(assign);

  comp_wk = week(complete);

  num_wks= (comp_wk - assign_wk) + 1;

  do i = assign_wk to comp_wk by 1;

    plot_week = i;

    output;

  end;

  label plot_week = 'Week';

return;

datalines;

101, 03mar2014,  aaa, 18apr2014

110, 11apr2014,  aaa, 08may2014

202, 18feb2014,  aaa, 03apr2014

330, 12feb2014,  aaa, 12apr2014

404, 01mar2014,  aaa, 07apr2014

550, 13jan2014,  bbb, 06may2014

606, 24apr2014,  bbb, 12jun2014

770, 21mar2014,  bbb, 15may2014

808, 28feb2014,  bbb, 07may2014

990, 01may2014,  bbb, 12may2014

;

run;

    

ods pdf file='c:\temp\plot_week.pdf';

proc sgplot data=testdata;

  title 'See Number of Projects Each Week';

  vbar plot_week /datalabel group=plot_week;

run;

ods pdf close;

avatar
Fluorite | Level 6

Thank you very much.

I think this code will work . I will give this a try

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 1565 views
  • 0 likes
  • 3 in conversation