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

I have a keep statement in a data step that keeps dropping a variable without giving me an error in the log?  Any ideas?

See attached document for copy of error log and data step program.

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

I don't know what environment you are working in, or which SAS version, or whether you are submitting this interactively or as a batch process, but cndv is beyond position 80 (as is cnd).

If you put one or both of those variables on a separate line, does it work correctly?

View solution in original post

6 REPLIES 6
art297
Opal | Level 21

Mike: no attachment came through.  But a keep statement "Specifies the variables to include in output SAS data sets"

Thus, it will only keep the variables that are specified and, in essence, drop all of the other variables.  The wouldn't be an error in such a case.

MikeCa
Calcite | Level 5

Thanks Art; in my instance I do have the variable in the keep statement but for some reason SAS drops the last variable in the keep statement -- see below.  I'm wondering why SAS would not read in the variable?

Below is the Original Code:

data ccma ;
    set table.operincCCD ;
  /*if month(ped) le month(&tytd2) ;*/

  format Year 4. ;
  Year = year(ped) ;
  format Mon 2. ;
  Mon = month(ped) ;
  CCM = UPCASE(CCM) ;
     if Year GE 2010 ;
     if (&LYBEG le ped le &TYEND) ;
     /*if (&tytd1 le ped le &tytd2) or (&lytd1 le ped le &lytd2) ;*/

keep co Year Mon ped ccm gas gash gast gasv gasdd oil oilh oilt oilv oildd cnd cndv cnddd
   othinc othincdd totrev totdd loe gen int tax dda dde uop aro
   totexp netinc mcfe taxcon taxprp taxsev taxest ;

Error Log looks like this -- No Errors but it dropped "cnddd" in keep statement?


47   /*
48   ** get data from table operinc ;
49   */
50      data ccma ;
51       set table.operincCCD ;
52            /*if month(ped) le month(&tytd2) ;*/
53
54            format Year 4. ;
55            Year = year(ped) ;
56            format Mon 2. ;
57            Mon = month(ped) ;
58            CCM = UPCASE(CCM) ;
59        if Year GE 2010 ;
60        if (&LYBEG le ped le &TYEND) ;
SYMBOLGEN:  Macro variable LYBEG resolves to mdy(01,01,11)
SYMBOLGEN:  Macro variable TYEND resolves to mdy(02,29,12)
61        /*if (&tytd1 le ped le &tytd2) or (&lytd1 le ped le &lytd2) ;*/
62
63           keep co Year Mon ped ccm gas gash gast gasv gasdd oil oilh oilt oilv oildd cnd cndv
64                           othinc othincdd totrev totdd loe gen int tax dda dde uop aro
65                           totexp netinc mcfe taxcon taxprp taxsev taxest ;
66
67          
71      run ;

NOTE: There were 449266 observations read from the data set TABLE.OPERINCCCD.
NOTE: The data set WORK.CCMA has 170952 observations and 36 variables.
NOTE: DATA statement used (Total process time):
      real time           24.04 seconds
      cpu time            1.15 seconds

Haikuo
Onyx | Level 15

Quite a mystery to me.  I know this is silly, as I can't copy OP's environment,  but I can't help trying it out and it is not happening to me.

255  data have;

256  array v(37) co Year Mon ped ccm gas gash gast gasv gasdd oil oilh oilt oilv oildd cnd cndv

256! cnddd

257     othinc othincdd totrev totdd loe gen int tax dda dde uop aro

258     totexp netinc mcfe taxcon taxprp taxsev taxest ;

259  do j=1 to 10;

260  do i=1 to 37;

261      v(i)=i;

262      end;

263      output;

264   end;

265   run;

NOTE: The data set WORK.HAVE has 10 observations and 39 variables.

NOTE: DATA statement used (Total process time):

      real time           0.01 seconds

      cpu time            0.01 seconds

266

267   data want;

268   set have;

269  keep co Year Mon ped ccm gas gash gast gasv gasdd oil oilh oilt oilv oildd cnd cndv cnddd

270     othinc othincdd totrev totdd loe gen int tax dda dde uop aro

271     totexp netinc mcfe taxcon taxprp taxsev taxest;

272     run;

NOTE: There were 10 observations read from the data set WORK.HAVE.

NOTE: The data set WORK.WANT has 10 observations and 37 variables.

NOTE: DATA statement used (Total process time):

      real time           0.01 seconds

      cpu time            0.01 seconds

Every thing seems normal to me.

art297
Opal | Level 21

I don't know what environment you are working in, or which SAS version, or whether you are submitting this interactively or as a batch process, but cndv is beyond position 80 (as is cnd).

If you put one or both of those variables on a separate line, does it work correctly?

MikeCa
Calcite | Level 5

Thank you -- I did put the attributes cnd cndv cnddd on a separate line and it took it.  The 80 character position must have been the issue.  Thanks again. 

manojinpec
Obsidian | Level 7

may eb this is because of environment .may the row gets truncated.

sas-innovate-2024.png

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.

 

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
  • 6 replies
  • 1331 views
  • 0 likes
  • 4 in conversation