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.
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 ;
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 ;
Maxim 1: Read the documentation.
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.
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 ;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.