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.
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?
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.
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
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.
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?
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.
may eb this is because of environment .may the row gets truncated.
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!
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.