BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sachin05t
Calcite | Level 5
libname HW5 'C:\Users\stadphal\Dropbox\MS\Fall 2018\2. Intro to SAS BIOE 813\HW5';
data hw5b;
set HW5.HW5b;
array AMT AMT1-AMT12;
array TAX TAX1-TAX12;
do i=1 to 6;
TAX[i]=AMT[i]*25/100;
end;
do i=7 to 12;
TAX[i]=AMT[i]*23/100;
end;
drop i;
output;
proc print;
run;

Problem: In the file attached, for each Employee, AMT1 through AMT12 give the monthly wage for year 2001. Write ONE data step to do the following:Use the Array statement to create 12 new variables TAX1 through TAX12 which are the taxes withheld for the months. Assume that the tax rate was 25% for the first 6 months, and it dropped to 23% for the last 6 months.

 

Question: Why does the output have a column 'i' with the value 13?

1 ACCEPTED SOLUTION

Accepted Solutions
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13
your welcome. Did your questions get resolved?

View solution in original post

9 REPLIES 9
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

I column is setup by your do loop.

I = 13 when the do loop finishes.

I should always = 1 step more that the upper bounds of the do loop.  Your do loop is by 1,  if you did by 2 then I would = 14 when this do loop finishes.

 

 

sachin05t
Calcite | Level 5

Thank you. So, is the logical solution just to use 'drop i'? OR can the program be changed in some way to avoid the 'i' column altogether?

Reeza
Super User

Your code has DROP i so something else is the issue if your output data set has i. 

Post your log.

 


@sachin05t wrote:

Thank you. So, is the logical solution just to use 'drop i'? OR can the program be changed in some way to avoid the 'i' column altogether?


 

sachin05t
Calcite | Level 5

Sure.. I've attached my log (without using the 'drop i' command).

 

 

NOTE: Copyright (c) 2002-2012 by SAS Institute Inc., Cary, NC, USA.
NOTE: SAS (r) Proprietary Software 9.4 (TS1M4 MBCS3170)
      Licensed to UNIVERSITY OF TENNESSEE SYSTEM - SFA - T&R, Site 70084768.
NOTE: This session is executing on the X64_10PRO  platform.



NOTE: Updated analytical products:

      SAS/STAT 14.2
      SAS/ETS 14.2
      SAS/OR 14.2
      SAS/IML 14.2
      SAS/QC 14.2

NOTE: Additional host information:

 X64_10PRO WIN 10.0.17134  Workstation

NOTE: SAS initialization used:
      real time           1.38 seconds
      cpu time            1.07 seconds

1    libname HW5 'C:\Users\stadphal\Dropbox\MS\Fall 2018\2. Intro to SAS BIOE 813\HW5';
NOTE: Libref HW5 was successfully assigned as follows:
      Engine:        V9
      Physical Name: C:\Users\stadphal\Dropbox\MS\Fall 2018\2. Intro to SAS BIOE 813\HW5
2    data hw5b;
3    set HW5.HW5b;
NOTE: Data file HW5.HW5B.DATA is in a format that is native to another host, or the file encoding does not match the session
      encoding. Cross Environment Data Access will be used, which might require additional CPU resources and might reduce
      performance.
4    array AMT AMT1-AMT12;
5    array TAX TAX1-TAX12;
6    do i=1 to 6;
7    TAX[i]=AMT[i]*25/100;
8    end;
9    do i=7 to 12;
10   TAX[i]=AMT[i]*23/100;
11   end;
12   output;

NOTE: There were 3 observations read from the data set HW5.HW5B.
NOTE: The data set WORK.HW5B has 3 observations and 26 variables.
NOTE: DATA statement used (Total process time):
      real time           0.03 seconds
      cpu time            0.03 seconds


13   proc print;
NOTE: Writing HTML Body file: sashtml.htm
14   run;

NOTE: There were 3 observations read from the data set WORK.HW5B.
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.46 seconds
      cpu time            0.37 seconds


I apologize..i used the 'drop i' command to get rid of the column.

 

But my question was - do we always get such extra columns after DO function?

 

VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

do I = 1 to 6 yes column named I

do x = 1 to 4 yes column named x

do ix = 1 to ?? yes column named ix

 

Astounding
PROC Star

As a matter of style, some programmers like to use:

 

do _n_=1 to 6;

 

Since _N_ is always dropped, you don't have to add a DROP statement.  The real advantage to using _N_ as the index to an array is in this sort of loop:

 

array nums {*} _numeric_;

do _n_=1 to dim(nums);

   nums{_n_}=0;

end;

 

It's comforting to know that (for practical purposes) _N_ will not be part of the list called _NUMERIC_.  If you chose i instead of _N_, and if i were one of the numeric variables in the array, the DO loop becomes an infinite loop.

sachin05t
Calcite | Level 5
Thanks a lot!
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13
your welcome. Did your questions get resolved?
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

place your drop statement like this to drop I from the table.

data hw5b (drop=I);

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 9 replies
  • 1131 views
  • 1 like
  • 4 in conversation