BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Sandeep77
Lapis Lazuli | Level 10

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.

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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 

--
Paige Miller

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26

Please show us a portion of the data, as working SAS data step code.

--
Paige Miller
Sandeep77
Lapis Lazuli | Level 10

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;

PaigeMiller
Diamond | Level 26

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?

--
Paige Miller
PaigeMiller
Diamond | Level 26

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 

--
Paige Miller
Sandeep77
Lapis Lazuli | Level 10
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!!
andreas_lds
PROC Star

@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 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

From SAS Users blog
Want more? Visit our blog for more articles like these.
5 Steps to Your First Analytics Project Using SAS

For SAS newbies, this video is a great way to get started. James Harroun walks through the process using SAS Studio for SAS OnDemand for Academics, but the same steps apply to any analytics project.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 404 views
  • 1 like
  • 3 in conversation