Hi all,
I am running a code and it runs without any error or warning but it does not give the correct output result. I am trying to find if the account number is coming for the first time in the table then mark it as 1 but the output results does not show 1 in any records. Here is my code.
data Trace_result_Flag;
set Trace_result_Sort;
by 'ACC NO'n Trace_dt;
if first.'ACC NO'n then Trace_Flag = 1;
run;
Even if the acc no is repeating, it does not flag it as 1. Please suggest.
Also, from now on, please please please show us the log, all of it for the DATA step that has a problem. Even if you think there is nothing in there of interest.
In this case, as I have played around with your problem, there is indeed a problem indicated in the log.
226 data Trace_result_Flag2; 227 set Trace_result_flag; 228 by 'ACC NO'n; 229 if first.'ACC NO'n then Trace_Flag = 1; 230 run; NOTE: Variable 'first.''ACC NO''n'n is uninitialized. NOTE: There were 10 observations read from the data set WORK.TRACE_RESULT_FLAG2. NOTE: The data set WORK.TRACE_RESULT_FLAG2 has 10 observations and 3 variables. NOTE: Compressing data set WORK.TRACE_RESULT_FLAG2 increased size by 100.00 percent. Compressed is 2 pages; un-compressed would require 1 pages. NOTE: DATA statement used (Total process time): real time 0.03 seconds cpu time 0.03 seconds
Try this:
if 'first.ACC NO'n then Trace_Flag = 1;
You would make your coding much easier, with fewer opportunities for typing errors or syntax errors, if you used variable names such as acc_no instead of 'ACC NO'n
Please show us a portion of the data, as working SAS data step code.
Data Trace_result_Flag;
infile cards expandtabs;
input 'ACC NO'n LIMA_result $ Trace_Flag;
datalines ;
1014824 NEG .
1014824 NEG .
1014824 NEG .
1064951 LAS .
1064951 LAS .
1064951 LAS .
1064951 LAS .
1064951 LAS .
1064951 LAS .
1064951 LAS .
;
run;
It does not help when the variable names and data set names change from your original post, to the later post. Could you please show us code and data that have consistent variable names and data set names?
Also, from now on, please please please show us the log, all of it for the DATA step that has a problem. Even if you think there is nothing in there of interest.
In this case, as I have played around with your problem, there is indeed a problem indicated in the log.
226 data Trace_result_Flag2; 227 set Trace_result_flag; 228 by 'ACC NO'n; 229 if first.'ACC NO'n then Trace_Flag = 1; 230 run; NOTE: Variable 'first.''ACC NO''n'n is uninitialized. NOTE: There were 10 observations read from the data set WORK.TRACE_RESULT_FLAG2. NOTE: The data set WORK.TRACE_RESULT_FLAG2 has 10 observations and 3 variables. NOTE: Compressing data set WORK.TRACE_RESULT_FLAG2 increased size by 100.00 percent. Compressed is 2 pages; un-compressed would require 1 pages. NOTE: DATA statement used (Total process time): real time 0.03 seconds cpu time 0.03 seconds
Try this:
if 'first.ACC NO'n then Trace_Flag = 1;
You would make your coding much easier, with fewer opportunities for typing errors or syntax errors, if you used variable names such as acc_no instead of 'ACC NO'n
@Sandeep77 wrote:
Cheers! 'first.Acc No'n worked. Actually, I generated a file from a dataset which required the format as Acc No and later on I was told to add few more information. Otherwise I would have kept it as acc_no. Thanks a lot!!
Variable names never need to have a blank or other fancy stuff in them. If a nice version of a name is required for printing (this includes export to excel) put the text into a label.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.