BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ManitobaMoose
Quartz | Level 8
Libname Learn'/folders/myfolders/SASData' ; 

Data Sales(keep = Date Amount) Inventory(keep = Partnumber Quantity) ; 
	infile '/folders/myfolders/SASData/mixed_recs.txt'  pad ; 
	Input @16 Code 2. @ ;
	If Code eq 1 then do ; 
		Out = Sales ;
		input @1 Date mmddyy10. 
		      @12 Amount 4.  ; 
		format Date mmddyy10. ;   
	end ; 
		
	
	Else if Code ne 1 then do ;
		Out = Inventory ;
		input @1 PartNumber $ 6.
		      @8 Quantity 3. ; 
	end ; 
run ; 

Data Sales_Only ; 
	Set Sales ; 
	Select ; 
	When (Missing(Date)) New = 1 ; 
	When (Not Missing(Date)) New = 2 ; 
	When (Missing(Amount)) New = 3 ;
	When (Not Missing(Amount)) New = 4 ; 
	Otherwise ; 
run ; 

Not sure where this is unclosed? Tx.

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

I think you missed an END

 

Data Sales_Only ; 
	Set Sales ; 
	Select ; 
	When (Missing(Date)) New = 1 ; 
	When (Not Missing(Date)) New = 2 ; 
	When (Missing(Amount)) New = 3 ;
	When (Not Missing(Amount)) New = 4 ; 
	Otherwise ; 
end; run ;

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20

I think you missed an END

 

Data Sales_Only ; 
	Set Sales ; 
	Select ; 
	When (Missing(Date)) New = 1 ; 
	When (Not Missing(Date)) New = 2 ; 
	When (Missing(Amount)) New = 3 ;
	When (Not Missing(Amount)) New = 4 ; 
	Otherwise ; 
end; run ;
Kurt_Bremser
Super User

Maxim 1: Read the documentation.

http://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.3&docsetId=lestmtsref&docsetTarget=p0...

SAS 9.4 and Viya 3.3 Programming Documentation - Data Step Programming - Data Step Statements - Dictionary of D. S. Statements

 

The presence of the necessary end; statement is prominent in the syntax section.

 

There is a very strong reason why Maxim 1 is actually the first.

Kurt_Bremser
Super User

And you should start writing code in a visually ordered style:

Data Sales_Only ; 
  Set Sales ; 
  Select ; 
    When (Missing(Date)) New = 1 ; 
    When (Not Missing(Date)) New = 2 ; 
    When (Missing(Amount)) New = 3 ;
    When (Not Missing(Amount)) New = 4 ; 
    Otherwise ; 
  end;
run ; 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 1661 views
  • 0 likes
  • 3 in conversation