BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
SAS_Novice22
Quartz | Level 8

Hi all,

 

Newbie here again. This SAS community has been super helpful. I have learned more in the last hour than I have watching many online YouTube tutorials so thank you so so much. I have one last issues for the day. I am attempting to generate a new variable based on responses to two other variables.

 

I am able to generate the new variable, however, I am running into problems with the coding that instructs the new variable what it is to be based on. 

 

This is for inclusion/exclusion criteria:

Subject will have had to indicate 'No' to using Drug A AND have taken 0,1, 2, or 3 doses of Drug B. Does that make sense?

 

Here is my code:

/**NEW DRUG B USER**/
DATA WORK.DRUG;
	SET DRUG;
	NEWDRUGB = .;
RUN;

DATA WORK.DRUG;
	SET DRUG;
	IF DRUGAYN="N" AND DRUGB="0" "1" "2" "3" THEN NEWDRUGB=1;
	ELSE NEWDRUGB = .;
RUN;

Here is the log output I am getting, can someone advise me what I might be doing wrong?

ERROR 388-185: Expecting an arithmetic operator.
ERROR 200-322: The symbol is not recognized and will be ignored.
ERROR 160-185: No matching IF-THEN clause.

Thank you again.

T.

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

First generic comment about error messages. Go to the log, copy the text of the entire step or procedure that generates the error including ALL the notes or messages as well as the error. Then on the forum open a text box using the </> icon that appears above the message window and paste the text there.

The text box is important to preserve the diagnostic characters that typically appear with some of the errors.

 

 

If you want to test if a variable takes one of multiple values the syntax is IN (<list of values goes here>). If the values are numeric do not include quotes around the values. So your syntax would be one of :

 

/* if the Drugb variable is character */
IF DRUGAYN="N" AND DRUGB in( "0" "1" "2" "3" ) THEN NEWDRUGB=1;

/*or if numeric*/
IF DRUGAYN="N" AND DRUGB in (0 1 2 3) THEN NEWDRUGB=1;

While learning SAS it is a good idea to NOT name the output data set the same as the source data. Syntax like

 

Data work.drug;
    set drug;
<other code>
run;

will completely replace the data set drug if there is no syntax error. Which may mean if there is a LOGIC error that you lose values, variables or records depending on what the other code actually does.

 

Recommend that unless you are working with very large data set to use something like:

Data work.drug_2;
    set drug;
<other code>
run;

Large in this case would be millions of records.

 

Note that if you do have  a "large" Drug set that you can test part of the code by limiting the number records to test with by using a data set option OBS. The following code only uses 25 records from the Drug set.

Data work.drug_2;
    set drug (obs=25);
<other code>
run;

 

 

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

We keep asking you to show us the ENTIRE log, and you haven't yet done so. We're trying to help you, but you have to help us too. Please show us the ENTIRE log, and make it a habit in the future.

--
Paige Miller
SAS_Novice22
Quartz | Level 8
Thank you, will try to do so with my next post. Thank you for the feedback.
Best wishes,
T.
ballardw
Super User

First generic comment about error messages. Go to the log, copy the text of the entire step or procedure that generates the error including ALL the notes or messages as well as the error. Then on the forum open a text box using the </> icon that appears above the message window and paste the text there.

The text box is important to preserve the diagnostic characters that typically appear with some of the errors.

 

 

If you want to test if a variable takes one of multiple values the syntax is IN (<list of values goes here>). If the values are numeric do not include quotes around the values. So your syntax would be one of :

 

/* if the Drugb variable is character */
IF DRUGAYN="N" AND DRUGB in( "0" "1" "2" "3" ) THEN NEWDRUGB=1;

/*or if numeric*/
IF DRUGAYN="N" AND DRUGB in (0 1 2 3) THEN NEWDRUGB=1;

While learning SAS it is a good idea to NOT name the output data set the same as the source data. Syntax like

 

Data work.drug;
    set drug;
<other code>
run;

will completely replace the data set drug if there is no syntax error. Which may mean if there is a LOGIC error that you lose values, variables or records depending on what the other code actually does.

 

Recommend that unless you are working with very large data set to use something like:

Data work.drug_2;
    set drug;
<other code>
run;

Large in this case would be millions of records.

 

Note that if you do have  a "large" Drug set that you can test part of the code by limiting the number records to test with by using a data set option OBS. The following code only uses 25 records from the Drug set.

Data work.drug_2;
    set drug (obs=25);
<other code>
run;

 

 

SAS_Novice22
Quartz | Level 8
Thank you for the helpful information and tips for posting. Much appreciated.
Have a great rest of your day.
T.

SAS Innovate 2025: Call for Content

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 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 4 replies
  • 911 views
  • 2 likes
  • 3 in conversation