BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
adzoyi
Calcite | Level 5

Can i get help with this SAS steps I wrote. I am new to SAS and I cannot figure out why I am having errors in the log.

 

data MSM_IDU;
set testing_data ;
format risk $10.;
if x742 ne '1' then risk='UNKNOWN';
else if g124 in ('1' '3') then do;
if g216a='1' then do;
if g402='1' then risk='MSM/IDU';
else risk='MSM';
end;
RUN;

1 ACCEPTED SOLUTION

Accepted Solutions
ghosh
Barite | Level 11

missing comma in the IN stmt and a missing end

else if g124 in ('1' , '3') then
* full code;
data MSM_IDU;
set testing_data ;
format risk $10.;
if x742 ne '1' then risk='UNKNOWN';
else if g124 in ('1', '3') then do;
if g216a='1' then do;
if g402='1' then risk='MSM/IDU';
else risk='MSM';
end;
end;
RUN;

 

View solution in original post

4 REPLIES 4
ed_sas_member
Meteorite | Level 14

Hi @adzoyi 

It's hard to say without some data to play with.

It seems that an 'end' statement is missing at the end of the program to close the Do loop:

data MSM_IDU;
	set testing_data;
	format risk $10.;

	if x742 ne '1' then risk='UNKNOWN';
	else if g124 in ('1' '3') then
		do;
			if g216a='1' then
				do;
					if g402='1' then
						risk='MSM/IDU';
					else
						risk='MSM';
				end;
		end; /* <<-- to be added*/
run;

Tip: to facilitate the identification of syntax error, do not hesitate to format your code and use proper indentation.

 

Best,

ghosh
Barite | Level 11

missing comma in the IN stmt and a missing end

else if g124 in ('1' , '3') then
* full code;
data MSM_IDU;
set testing_data ;
format risk $10.;
if x742 ne '1' then risk='UNKNOWN';
else if g124 in ('1', '3') then do;
if g216a='1' then do;
if g402='1' then risk='MSM/IDU';
else risk='MSM';
end;
end;
RUN;

 

ballardw
Super User

When you get an error best practice for this forum is to copy from the Log the data step or Proc code along with all the messages. The Paste into a code box opened with the </> icon to preserve formatting. The main message windows will reformat text so the diagnostic characters that SAS often supplies do not appear in the correct place.

 

An example:

190  data junk;
191     set sashelp.class;
192     if sex='F' then do;
193        junk=age*weight;
194  run;

194  run;
        -
        117
ERROR 117-185: There was 1 unclosed DO block.

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.JUNK may be incomplete.  When this step was stopped there were 0
         observations and 6 variables.
WARNING: Data set WORK.JUNK was not replaced because this step was stopped.

The message is moderately clear: there was Do statement without a matching End to close the Do block.

The diagnostic characters appear with the Run statement in this case as it ends the data step and is the first thing SAS can indicate as "not an end statement".

AMSAS
SAS Super FREQ

Looks like other community members beat me to the punch.
I'd like to add it's a good idea to format/indent your code which makes it easier to debug

data MSM_IDU;
	set testing_data ;
	format risk $10.;
	if x742 ne '1' then 
		risk='UNKNOWN';
	else 
	if g124 in ('1', /* <-- NEED THIS COMMA HERE */ '3') then do;
		if g216a='1' then do;
			if g402='1' then risk='MSM/IDU';
			else risk='MSM';
		end;
	end ; /* <-- NEED THIS EXTRA END */
RUN;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1438 views
  • 0 likes
  • 5 in conversation