BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
user40
Calcite | Level 5
proc sql;
  create table solution as
  select lopenummer, daydiff , indiff, min, maks, sum(daydiff) as sum_daydiff 

  from   want2
  group by lopenummer , indiff;
quit;

I want to sum number of days within each ID and indiff, but this does not work. I only got 

 

user40_0-1667375750460.png

But the last row should have sum daydiff to 626 and not 85, 39 and 502 in three different rows. How can i get this? 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Reading the thread again, perhaps you want (instead of your SQL code) this:

 

proc summary data=test nway;
    class lopenummer;
    var indiff min maks daydiff;
    output out=want sum=;
run;

 

but as I don't have working data, I can't be sure that provides the answer you want.

 

 

--
Paige Miller

View solution in original post

10 REPLIES 10
PeterClemmensen
Tourmaline | Level 20

Either indiff or lopenummer is not exactly equal across the three rows. My guess is that indiff is a calculated column and not exactly equal.

user40
Calcite | Level 5

It is equal.

PeterClemmensen
Tourmaline | Level 20

How was indiff calculated?

user40
Calcite | Level 5

Indiff (days for each ami incidence for example) is a fast numeric variable and are not calculated. This variable is variable that are the same for the same incidence in each case.

PeterClemmensen
Tourmaline | Level 20

Ok. Either that or you have to include min, max and so on in your group by clause. 

 

I can't run your code because you did not post any sample data to work with.

user40
Calcite | Level 5

user40_0-1667390390985.png

 

Hi 

 

I try to sum daydiff variable in respect for lopenummer and indiff. Then I have this dataset, 

 

 

data test; 
input lopenummer , indiff, min maks, daydiff 
ID1,  6495, 6130, 6860,  614 
ID2 7739, 7374, 8104, 19 
ID3, 9478, 9113, 9843, 85
ID3, 9478, 9113, 9843, 39
ID3, 9478, 9113, 9843, 502;
run;

I want to sum the daydiff variable regards group by lopenummer variable and indiff variable. I thinked that this would be like this: 

 

proc sql; 
create table want as 
select lopenummer, indiff, min , maks, daydiff, 
from test 
order by lopenummer , indiff; 
quit; 

But this do not work. What is wrong in my code? 

PaigeMiller
Diamond | Level 26

@user40 wrote:

user40_0-1667390390985.png

 

Hi 

 

I try to sum daydiff variable in respect for lopenummer and indiff. Then I have this dataset, 

 

 

data test; 
input lopenummer , indiff, min maks, daydiff 
ID1,  6495, 6130, 6860,  614 
ID2 7739, 7374, 8104, 19 
ID3, 9478, 9113, 9843, 85
ID3, 9478, 9113, 9843, 39
ID3, 9478, 9113, 9843, 502;
run;

I want to sum the daydiff variable regards group by lopenummer variable and indiff variable. I thinked that this would be like this: 


Would you please be so kind as to provide WORKING code for your data. This code doesn't work for a number of reasons, including a missing semi-colon.

 

 

proc sql; 
create table want as 
select lopenummer, indiff, min , maks, daydiff, 
from test 
order by lopenummer , indiff; 
quit; 

But this do not work. What is wrong in my code? 

 

I get an error in the LOG

 

1076  proc sql;
1077  create table want as
1078  select lopenummer, indiff, min , maks, daydiff,
1079  from test
           ----
           22
           76
ERROR 22-322: Syntax error, expecting one of the following: a quoted string, !, !!, &, (, *, **, +, ',', -, '.', /, <, <=, <>, =, >, >=, ?, AND, AS,
              BETWEEN, CONTAINS, EQ, EQT, FORMAT, FROM, GE, GET, GT, GTT, IN, INFORMAT, INTO, IS, LABEL, LE, LEN, LENGTH, LET, LIKE, LT, LTT, NE,
              NET, NOT, NOTIN, OR, TRANSCODE, ^, ^=, |, ||, ~, ~=.

ERROR 76-322: Syntax error, statement will be ignored.

1080  order by lopenummer , indiff;
1081  quit;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds

so if you fix that by removing the semi-colon after daydiff, does it work then?

--
Paige Miller
PaigeMiller
Diamond | Level 26

Reading the thread again, perhaps you want (instead of your SQL code) this:

 

proc summary data=test nway;
    class lopenummer;
    var indiff min maks daydiff;
    output out=want sum=;
run;

 

but as I don't have working data, I can't be sure that provides the answer you want.

 

 

--
Paige Miller
user40
Calcite | Level 5
data test; 
input lopenummer , indiff, min maks, daydiff 
ID1,  6495, 6130, 6860,  614 
ID2 7739, 7374, 8104, 19 
ID3, 9478, 9113, 9843, 85
ID3, 9478, 9113, 9843, 39
ID3, 9478, 9113, 9843, 502;
run;

 

proc sql; 
create table want as 
select lopenummer, indiff, min , maks, daydiff 
from test 
order by lopenummer , indiff; 
quit; 

Now then?

PaigeMiller
Diamond | Level 26

@user40 wrote:
data test; 
input lopenummer , indiff, min maks, daydiff 
ID1,  6495, 6130, 6860,  614 
ID2 7739, 7374, 8104, 19 
ID3, 9478, 9113, 9843, 85
ID3, 9478, 9113, 9843, 39
ID3, 9478, 9113, 9843, 502;
run;

 


Obviously, you did not actually run the code for TEST, a required step to meet the criterion that it is WORKING code. Please fix all the errors.

--
Paige Miller

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 10 replies
  • 605 views
  • 0 likes
  • 3 in conversation