BookmarkSubscribeRSS Feed
Sandeep77
Lapis Lazuli | Level 10

Hi all,

I am comparing App_address, Sup_address, Original_address and Current_address. I want to find if the title in all the four dataset is blank then 0 and if any one of the dataset have a title then flag it as 1. I am trying the below code but it is showing error. Can you please suggest?

data Title_comparison;
set App_address Sup_address Original_address Current_address; 

if App_address: title ne "" or Sup_address: title ne "" or Original_address: title ne "" or Current_address: title ne "" then do; 
flag = 1;
end;
else flag = 0;  
run;
Error log:
29         data Title_comparison;
30         set App_address Sup_address Original_address Current_address;
31         
32         if App_address: title ne "" or Sup_address: title ne "" or Original_address: title ne "" or Current_address: title ne ""
                         _
                         22
                         76
32       ! then do;
ERROR 22-322: Syntax error, expecting one of the following: <, <=, =, >, >=, EQ, GE, GT, IN, LE, LT, NE, NG, NL, NOTIN, ^=, ~=.  

ERROR 76-322: Syntax error, statement will be ignored.

33         flag = 1;
34         end;
           ___
           161
ERROR 161-185: No matching DO/SELECT statement.

35         else flag = 0;
36         run;

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.TITLE_COMPARISON may be incomplete.  When this step was stopped there were 0 observations and 32 
         variables.
4 REPLIES 4
sbxkoenk
SAS Super FREQ

What is the "title"?
You need Variable names in your if statement.

 

Koen

Sandeep77
Lapis Lazuli | Level 10

Title is a column in the dataset. Can you explain more about variable name in if statement as I am not very good with SAS. Thanks

sbxkoenk
SAS Super FREQ

Hello,

 

Are you sure you need a SET statement?
You are vertically appending 4 datasets
(work.App_address , work.Sup_address , work.Original_address and work.Current_address).

 

If title is a variable name in all 4, you simply need :

if strip(title) NE '' then ... ;

 

But maybe you want to merge these datasets (horizontally) based on a key-variable (or multiple key-variables)?

And maybe you want to flag the observations that have the same key-combination and missing titles in all 4 datasets

 

Koen

 
ballardw
Super User

Is this a ChatGpt or similar generated code?

The : list builder with variable names only works in a place where a list is acceptable such as an array definition, keep/drop list , format assignment or function like SUM or MEAN that will accept a list of variables.

 

So every use of : in this statement is illegal syntax and I am not sure what you thought it was attempting to do.

if App_address: title ne "" or Sup_address: title ne "" or Original_address: title ne "" or Current_address: title ne "" then do; 
flag = 1;

 Are you trying to check if every variable in the data set App_address is doing something?

 

You really don't access anything related to a dataset name in the body of a data step. You can add a variable using the IN= option to indicate if an observation has a contribution from a dataset but once the variables on are in the data vector the actual data set name is moot.