BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Nipun22
Obsidian | Level 7

data cars;
set sashelp.cars;
run;

proc report data = cars;
col ('Report submitted by telecom pvt ltd' make type origin newsale msrp,(min max mean));
define make/ group;
define type/ group;
define origin/ group;
define newsale/ computed format=dollar7.;
compute newsale;
newsale = msrp + 100;
endcomp;
run;

 

I saw that I can do this by using the across option in define statement of any of the variable and just mention the column number but I want to do this way by mentioning the variable name. Any logic with little explanation would be appreciated

Nipun22_0-1722344138915.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

For a variable that is being aggregated within a group you need to tell PROC REPORT which stat you want.  If you want the SUM then add .SUM to the variable name in the code block.

data cars;
set sashelp.cars (obs=40);
run;

proc report data = cars;
col ('Report submitted by telecom pvt ltd' make type origin msrp
  newsale) 
;
define make/ group;
define type/ group;
define origin/ group;
define newsale / computed format=dollar10.;
compute newsale;
  newsale = msrp.sum + 100;
endcomp;
run;

Result

           Report submitted by telecom pvt ltd
  Make           Type      Origin      MSRP     newsale
  Acura          SUV       Asia     $36,945     $37,045
                 Sedan     Asia    $173,860    $173,960
                 Sports    Asia     $89,765     $89,865
  Audi           Sedan     Europe  $534,400    $534,500
                 Sports    Europe  $198,520    $198,620
                 Wagon     Europe   $89,930     $90,030
  BMW            SUV       Europe   $89,195     $89,295
                 Sedan     Europe  $490,740    $490,840

View solution in original post

14 REPLIES 14
PaigeMiller
Diamond | Level 26

You did not get an ERROR, you got a NOTE.

 

From now on when you get an ERROR or WARNING or NOTE that you don't understand, please show us the log for this PROC, including the code as it appears in the LOG. Showing us ERROR or WARNING or NOTE messages detached from the code is not as helpful.

 

A couple of problems here:

  • MSRP is not defined as an across variable.
  • When you do a COMPUTE on variables, the COMPUTE can only use variables to the left in the COLUMNS statement. Since MSRP is to the right of NEWSALE in the columns statement, it cannot be used.

When you define an across variable, this means that many of the columns in your PROC REPORT cannot be referred to by name, they can only be referred to by _Cn_

--
Paige Miller
Nipun22
Obsidian | Level 7

I had already attached the screenshot for relevant issues in first place still if you want here is the full log

I have moved the NEWSALE variable to the right of the MSRP still getting the same note as below

Nipun22_0-1722345562396.png

 

PaigeMiller
Diamond | Level 26

This is not the full log. I want to see the entire log for this PROC, including the code as it appears in the log. And also please provide the log as text (not as screen capture), pasted into the window that appears when you click on the </> icon.

2021-11-26 08_27_29-Reply to Message - SAS Support Communities — Mozilla Firefox.png

--
Paige Miller
Nipun22
Obsidian | Level 7
1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 68         
 69         data cars;
 70         set sashelp.cars;
 71         run;
 
 NOTE: There were 428 observations read from the data set SASHELP.CARS.
 NOTE: The data set WORK.CARS has 428 observations and 15 variables.
 NOTE: DATA statement used (Total process time):
       real time           0.00 seconds
       user cpu time       0.00 seconds
       system cpu time     0.00 seconds
       memory              845.06k
       OS Memory           22180.00k
       Timestamp           07/30/2024 01:27:47 PM
       Step Count                        161  Switch Count  2
       Page Faults                       0
       Page Reclaims                     109
       Page Swaps                        0
       Voluntary Context Switches        10
       Involuntary Context Switches      0
       Block Input Operations            0
       Block Output Operations           272
       
 
 72         
 73         proc report data = cars;
 74         col ('Report submitted by telecom pvt ltd' make type origin msrp,(min max mean) newsale);
 75         define make/ group;
 76         define type/ group;
 77         define origin/ group;
 78         define newsale/ computed format=dollar7.;
 79         compute newsale;
 80         newsale = msrp + 100;
 81         endcomp;
 82         run;
 
 NOTE: Variable msrp is uninitialized.
 NOTE: Missing values were generated as a result of performing an operation on missing values.
       Each place is given by: (Number of times) at (Line):(Column).
       114 at 1:17   
 NOTE: There were 428 observations read from the data set WORK.CARS.
 NOTE: PROCEDURE REPORT used (Total process time):
       real time           0.08 seconds
       user cpu time       0.09 seconds
       system cpu time     0.01 seconds
       memory              9112.32k
       OS Memory           31160.00k
       Timestamp           07/30/2024 01:27:47 PM
       Step Count                        162  Switch Count  1
       Page Faults                       0
       Page Reclaims                     2128
       Page Swaps                        0
       Voluntary Context Switches        18
       Involuntary Context Switches      0
       Block Input Operations            0
       Block Output Operations           48
       
 
 83         
 84         OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 94         
PaigeMiller
Diamond | Level 26

Please read carefully, I don't want the log of the entire program, I want the entire log for that PROC.

 

UPDATE: See response from @ballardw 

 

--
Paige Miller
Nipun22
Obsidian | Level 7

Yes sure, I just wanted this kind of table where just a new variable NEWSALE is added at the last which will be calculated as MSRP + 100. Everything is good but the log keeps saying two things due to which the NEWSALE variable is empty - 

  • Variable msrp is uninitialized.
  • NOTE: Missing values were generated as a result of performing an operation on missing values. Each place is given by (Number of times) at (Line):(Column).Nipun22_0-1722346926515.png

hope I you understood the problem and purpose of the code now

data_null__
Jade | Level 19

This is the generated DEFINE for the alias XMSRP.   Don't know if this helps or not.  

DEFINE xmsrp / SUM FORMAT= DOLLAR8. WIDTH=8 SPACING=2 RIGHT "MSRP" ;

 

 

data cars;
   set sashelp.cars;
   run;

proc report data = cars;
   col ('Report submitted by telecom pvt ltd' make type origin msrp=xmsrp newsale msrp,(min max mean));
   define make/ group;
   define type/ group;
   define origin/ group;
   define newsale/ computed format=dollar7.;
      compute newsale;
      newsale = xmsrp + 100;
      endcomp;
   run;

Capture.PNG

 

PROC REPORT DATA=WORK.CARS LS=132 PS=60  SPLIT="/" CENTER ;
COLUMN  ( ("Report submitted by telecom pvt ltd"  Make Type Origin MSRP=xmsrp newsale MSRP,( min max mean ) ) );
 
DEFINE  Make / GROUP FORMAT= $13. WIDTH=13    SPACING=2   LEFT "Make" ;
DEFINE  Type / GROUP FORMAT= $8. WIDTH=8     SPACING=2   LEFT "Type" ;
DEFINE  Origin / GROUP FORMAT= $6. WIDTH=6     SPACING=2   LEFT "Origin" ;
DEFINE  xmsrp / SUM FORMAT= DOLLAR8. WIDTH=8     SPACING=2   RIGHT "MSRP" ;
DEFINE  newsale / COMPUTED FORMAT= DOLLAR7. WIDTH=7     SPACING=2   RIGHT "newsale" ;
DEFINE  MSRP / SUM FORMAT= DOLLAR8. WIDTH=8     SPACING=2   RIGHT "MSRP" ;
DEFINE  min / FORMAT= DOLLAR8. WIDTH=9     SPACING=2   RIGHT "min" ;
DEFINE  max / FORMAT= DOLLAR8. WIDTH=9     SPACING=2   RIGHT "max" ;
DEFINE  mean / FORMAT= DOLLAR8. WIDTH=9     SPACING=2   RIGHT "mean" ;

COMPUTE  newsale;
newsale = xmsrp +100;
ENDCOMP;
ballardw
Super User

WHICH statistic of MSRP did you want to use for Newsale??? You have msrp,(min max mean) so there are three statistics in play.

After fixing the order of the variables on the Columns statement here is an example of using ONE of the statistics, in this case the MEAN to calculate Newsale.

You are getting an "uninitialized" note because you did not provide enough information in the Compute block.

proc report data = cars;
   columns  make type origin msrp,(min max mean) newsale ;
   define make/ group;
   define type/ group;
   define origin/ group;

   define newsale/ computed format=dollar7.;
   compute newsale;
      newsale = msrp.mean + 100;
   endcomp;
run;
Nipun22
Obsidian | Level 7
Yes I know this syntax. I could have done this but I want different results. Please check my last reply where I have described by needs briefly
ballardw
Super User

@Nipun22 wrote:
Yes I know this syntax. I could have done this but I want different results. Please check my last reply where I have described by needs briefly

You have not clearly enough stated your requirement for Proc Report to calculate. To use any sort of compute to calculate you must meet the syntax rules. You have not stated what MSRP+100 in this context actually means. Which is in effect what Proc Report is also complaining about.

I don't know what number you expect to show for Newsale. Repeating the same incomplete information does not provide any clue as to a possible solution, if at all possible. The Note SAS is providing about "MSRP is uninitialized" is a clue that more information about how you expect to use MSRP is required.

 

Because you have used the syntax msrp,(min max mean) you have limited the easy to get values as MSRP.Min, MSRP.MAX and MSRP.MEAN as shown in the compute block that does not generate the note. IF you want something else then you have to find a way to provide the information to us and then we may come up with the procedure requirements. But without them we can't.

 

Computers are dumb. You have to tell them what you want. Regardless of what the AI folks are promising they still cannot read your mind as to what value is supposed to appear in the column Newsales.

Nipun22
Obsidian | Level 7

Okay I have stated my issue in the simplest way I could. Let's take it this way forget whatever we have discussed till now. Here I am giving you this code of a table

 

data cars;
set sashelp.cars;
run;

proc report data = cars;
col ('Report submitted by telecom pvt ltd' make type origin msrp,(min max mean));
define make/ group;
define type/ group;
define origin/ group;
run;

write syntax for new variable NEWSALE calculated as below-

NEWSALE = MSRP + 100;

In words - I want to add or increment MSRP by 100 and store it in a new variable called NEWSALE

It is as simple as it sounds. Just write whatever you know. Also, let me know if it is programmatically possible or not.

ballardw
Super User

@Nipun22 wrote:

Okay I have stated my issue in the simplest way I could. Let's take it this way forget whatever we have discussed till now. Here I am giving you this code of a table

 

data cars;
set sashelp.cars;
run;

proc report data = cars;
col ('Report submitted by telecom pvt ltd' make type origin msrp,(min max mean));
define make/ group;
define type/ group;
define origin/ group;
run;

write syntax for new variable NEWSALE calculated as below-

NEWSALE = MSRP + 100;

In words - I want to add or increment MSRP by 100 and store it in a new variable called NEWSALE

It is as simple as it sounds. Just write whatever you know. Also, let me know if it is programmatically possible or not.


Still not a clear description of the value that Newsale should have. Because you are in a Procedure like Report you have to define it in terms of what the procedure can do/allow. As a person, I don't know what you want as it is not clear whether you want to

1) add 100 to a displayed statistic based on MSRP (easy but with the statistics  you have shown limits it to those three and would need to be stated)

2) add 100 to a not-displayed statistic, which statistic would need to be stated and requires some additions to the code but likely not difficult

3) something else that is not intuitively obvious that is quite likely to require a bit more coding. A description, starting with the data set of how to calculate it by hand is needed.

Tom
Super User Tom
Super User

For a variable that is being aggregated within a group you need to tell PROC REPORT which stat you want.  If you want the SUM then add .SUM to the variable name in the code block.

data cars;
set sashelp.cars (obs=40);
run;

proc report data = cars;
col ('Report submitted by telecom pvt ltd' make type origin msrp
  newsale) 
;
define make/ group;
define type/ group;
define origin/ group;
define newsale / computed format=dollar10.;
compute newsale;
  newsale = msrp.sum + 100;
endcomp;
run;

Result

           Report submitted by telecom pvt ltd
  Make           Type      Origin      MSRP     newsale
  Acura          SUV       Asia     $36,945     $37,045
                 Sedan     Asia    $173,860    $173,960
                 Sports    Asia     $89,765     $89,865
  Audi           Sedan     Europe  $534,400    $534,500
                 Sports    Europe  $198,520    $198,620
                 Wagon     Europe   $89,930     $90,030
  BMW            SUV       Europe   $89,195     $89,295
                 Sedan     Europe  $490,740    $490,840

Nipun22
Obsidian | Level 7
Thank you so much man. That's what I have been explaining for so long just to add 100 to the MSRP that's it.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 14 replies
  • 1146 views
  • 5 likes
  • 5 in conversation