Hello,
I am a new SAS coder working on a homework problem that has stumped me. The question is: Write SAS code which will read in 10 observations from the ‘SASHelp.Cars’ data set, starting with the 70th observation.
Below is the code I wrote for my answer:
DATA WORK.Illus;
SET SASHelp.Cars (FIRSTOBS = 70 OBS = 10);
RUN;
However, when I run this code, my log gives me an error and two warnings:
Errors (1) Warnings (2) Notes (2) 1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; 68 69 DATAWORK.Illus; 70 SETSASHelp.Cars(FIRSTOBS = 70OBS = 10); ERROR: FIRSTOBS option > OBS option - no data to read from file SASHELP.CARS. 71 RUN; NOTE: The SAS System stopped processing this step because of errors. WARNING: The data set WORK.ILLUS may be incomplete. When this step was stopped there were 0 observations and 0 variables. WARNING: Data set WORK.ILLUS was not replaced because this step was stopped. NOTE: DATA statement used (Total process time): real time 0.00 seconds user cpu time 0.00 seconds system cpu time 0.00 seconds memory 530.93k OS Memory 21152.00k Timestamp 10/26/2023 07:03:03 PM Step Count 42 Switch Count 0 Page Faults 0 Page Reclaims 52 Page Swaps 0 Voluntary Context Switches 0 Involuntary Context Switches 0 Block Input Operations 0 Block Output Operations 8 72 73 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; 83
What am I missing? Thanks for any help.
70 SETSASHelp.Cars(FIRSTOBS = 70OBS = 10); ERROR: FIRSTOBS option > OBS option - no data to read from file SASHELP.CARS.
There are two problems here ... first is that there is no space after FIRSTOBS=70 (although strangely that doesn't seem to be an error)
The second is explained by the ERROR message. You can't have FIRSTOBS > OBS, so you must have OBS to be greater than or equal to FIRSTOBS. With that hint, what do you think OBS should be here?
70 SETSASHelp.Cars(FIRSTOBS = 70OBS = 10); ERROR: FIRSTOBS option > OBS option - no data to read from file SASHELP.CARS.
There are two problems here ... first is that there is no space after FIRSTOBS=70 (although strangely that doesn't seem to be an error)
The second is explained by the ERROR message. You can't have FIRSTOBS > OBS, so you must have OBS to be greater than or equal to FIRSTOBS. With that hint, what do you think OBS should be here?
Oh! 79? FIRST OBS = 70, +9 gives me 10 observations. Got it. Thank you so much!
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
For SAS newbies, this video is a great way to get started. James Harroun walks through the process using SAS Studio for SAS OnDemand for Academics, but the same steps apply to any analytics project.
Find more tutorials on the SAS Users YouTube channel.