BookmarkSubscribeRSS Feed
kgrover
Calcite | Level 5

I'm trying to create a flag variable for respondents that answered S3 = 1 and Q11 ne 1 and if either timer variables had <1 

 

I've tried the following syntax, which doesn't seem to be working.

 

 

proc SQL;
create table flagstemcell as
select S3, Q11, treatment_feature_Timer, treatment_benefit_Timer, treatment_benefit_2_Timer, complete_response_information_Ti, treatment_side_effects_1_Timer
	treatment_side_effects_2_Timer, treatment_side_effects_3_Timer, treatment_risk_Timer 
	When S3 = 1 and Q11 NE 1 and treatment_feature_Timer <10 or treatment_benefit_Timer <10 or treatment_benefit_2_Timer <10 
	or complete_response_information_Ti <10 or treatment_side_effects_1_Timer < 10 	treatment_side_effects_2_Timer <10 or treatment_side_effects_3_Timer or treatment_risk_Timer 
from MM1;
group by record;
quit; 

 

3 REPLIES 3
PaigeMiller
Diamond | Level 26

Please explain what is not working.

 

If there is an error in the log, please show us the log of this PROC SQL, all of it, not selected parts. To show us the log, please format it properly so that it is readable by copying the log as text and pasting it into the window that appears when you click on the </> icon. DO NOT SKIP THIS STEP.

 

If the problem is that it gives the wrong output, please explain in detail.

--
Paige Miller
Reeza
Super User

Please include your log when you have errors.

 

Issues:

  1. Semicolons that end your query early
  2. Clauses out of order (SELECT/FROM/WHERE/GROUP/ORDER) is a rough order, in the query posted WHERE is before FROM
  3. Missing brackets for the OR statements
  4. Missing OR or comparisons for some of the timer variables.

I've cleaned it up somewhat but you may still have logical and syntax issues here. If so, and you cannot debug it based on the log make sure you post both the code and log in future responses.

 

proc SQL;
create table flagstemcell as
select S3, Q11, treatment_feature_Timer, treatment_benefit_Timer, treatment_benefit_2_Timer, complete_response_information_Ti, treatment_side_effects_1_Timer
	treatment_side_effects_2_Timer, treatment_side_effects_3_Timer, treatment_risk_Timer 
	
from MM1

When S3 = 1 and Q11 NE 1 and (treatment_feature_Timer <10 or treatment_benefit_Timer <10 or treatment_benefit_2_Timer <10 
	or complete_response_information_Ti <10 or treatment_side_effects_1_Timer < 10 or	treatment_side_effects_2_Timer <10 or treatment_side_effects_3_Timer<10 or treatment_risk_Timer <10

group by record;
quit; 

@kgrover wrote:

I'm trying to create a flag variable for respondents that answered S3 = 1 and Q11 ne 1 and if either timer variables had <1 

 

I've tried the following syntax, which doesn't seem to be working.

 

 

proc SQL;
create table flagstemcell as
select S3, Q11, treatment_feature_Timer, treatment_benefit_Timer, treatment_benefit_2_Timer, complete_response_information_Ti, treatment_side_effects_1_Timer
	treatment_side_effects_2_Timer, treatment_side_effects_3_Timer, treatment_risk_Timer 
	When S3 = 1 and Q11 NE 1 and treatment_feature_Timer <10 or treatment_benefit_Timer <10 or treatment_benefit_2_Timer <10 
	or complete_response_information_Ti <10 or treatment_side_effects_1_Timer < 10 	treatment_side_effects_2_Timer <10 or treatment_side_effects_3_Timer or treatment_risk_Timer 
from MM1;
group by record;
quit; 

 


 

Tom
Super User Tom
Super User

First format your code neatly so you can more easily see and fix the obvious typos and syntax errors.

proc SQL;
create table flagstemcell as
select
    S3
  , Q11
  , treatment_feature_Timer
  , treatment_benefit_Timer
  , treatment_benefit_2_Timer
  , complete_response_information_Ti
  , treatment_side_effects_1_Timer
  	treatment_side_effects_2_Timer
  , treatment_side_effects_3_Timer
  , treatment_risk_Timer 
  	When S3 = 1
     and Q11 NE 1
     and treatment_feature_Timer <10
      or treatment_benefit_Timer <10
      or treatment_benefit_2_Timer <10 
  	  or complete_response_information_Ti <10
      or treatment_side_effects_1_Timer < 10 	
         treatment_side_effects_2_Timer <10 
      or treatment_side_effects_3_Timer 
      or treatment_risk_Timer 
  from MM1
;
  group by record
;
quit; 

Then add grouping () to your conditions so they make sense.  If you code 

A and B or C or D 

What are you asking for?  

Are you asking for 

(A and B) or C or D 

or 

A and (B or C or D)

?

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 3 replies
  • 1539 views
  • 0 likes
  • 4 in conversation