can anyone help me in writing the following program
* Using correct input option create a SAS data set named icecream using data file (Sales.dat);
* Use variables: Flavor, Location, BoxesSold
* Output only 5 observations starting with third observation.
data icecream;
set sales(firstobs=3 obs=7);
keep flavor location boxessold;
run;
or something like
DATA icecream;
INFILE 'c:\MyRawData\sales.dat';
INPUT (flavor location) ($) boxessold firstobs=3 obs=7;
RUN;
This worked
title 'dataset ICECREAM';
data iceceam;
infile '/folders/myfolders/data/Sales1.dat' firstobs=3 obs=7 ;
input flavor $11. location boxessold ;
run;
proc print ;
run;
Thanks for the effort.
@rk7 That was @novinosrin answer to you yesterday. Marking your own answer as correct isn't appropriate in this situation.
There is a mistake in the solution he offered. The firstobs and obs dataset options are declared in input statement where as it should be in infile statement. I have no problem in removing the solution tag if @novinosrin changes his answer.
Thanks
Nope, fair enough. Thanks for clarifying 🙂
Hahaha, No worries. I'm here to learn like you are. Also being a graduate student, community credit is pale in comparison to how much i feel inferior when i notice people like reeza, art t, xia keshan , haikuo, chris nz, mkeintz, astounding etc with their slick answers. The next semester is what I am hoping to gain in a big way to be able to solve harder questions when I move on to take courses in Regression, principal components, time series and forecasting etc. Join the club if you like 🙂 . We are peers unlike the super list I mentioned above
what a humble answer. loved it. It will remain an unanswered question
Two ways:
FirstOBS and OBS via a data step
Or read it all in and filter afterwards using IF statements and _N_.
@rk7 wrote:
can anyone help me in writing the following program
* Using correct input option create a SAS data set named icecream using data file (Sales.dat);
* Use variables: Flavor, Location, BoxesSold
* Output only 5 observations starting with third observation.
This is the code I have written
data icecream;
INFILE '/folders/myfolders/data/Sales1.dat';
INPUT flavor $10. location boxessold;
if _N_ = 3 to 8 then output;
end;
RUN;
proc print;
run;
This is the output I got
Obs flavor location
Chocolate | 213 | 123 |
Chocolate | 213 | 123 |
Chocolate | 213 | 123 |
Chocolate | 213 | 123 |
Chocolate | 213 | 123 |
Chocolate | 213 | 123 |
Vanilla | 213 | 512 |
Vanilla | 213 | 512 |
Vanilla | 213 | 512 |
Vanilla | 213 | 512 |
Vanilla | 213 | 512 |
Vanilla | 213 | 512 |
Pecan | 415 | 242 |
Pecan | 415 | 242 |
Pecan | 415 | 242 |
Pecan | 415 | 242 |
Pecan | 415 | 242 |
Pecan | 415 | 242 |
Choco 2 | 13 | 123 |
Choco 2 | 13 | 123 |
Choco 2 | 13 | 123 |
Choco 2 | 13 | 123 |
Choco 2 | 13 | 123 |
Choco 2 | 13 | 123 |
Strawberry | 213 | 512 |
Strawberry | 213 | 512 |
Strawberry | 213 | 512 |
Strawberry | 213 | 512 |
Strawberry | 213 | 512 |
Strawberry | 213 | 512 |
Coffee | 415 | 242 |
Coffee | 415 | 242 |
Coffee | 415 | 242 |
Coffee | 415 | 242 |
Coffee | 415 | 242 |
Coffee | 415 | 242 |
nuts | 213 | 123 |
nuts | 213 | 123 |
nuts | 213 | 123 |
nuts | 213 | 123 |
nuts | 213 | 123 |
nuts | 213 | 123 |
almonds | 213 | 512 |
almonds | 213 | 512 |
almonds | 213 | 512 |
almonds | 213 | 512 |
almonds | 213 | 512 |
almonds | 213 | 512 |
mint | 415 | 242 |
mint | 415 | 242 |
mint | 415 | 242 |
mint | 415 | 242 |
mint | 415 | 242 |
mint | 415 | 242 |
Fudge | 213 | 123 |
Fudge | 213 | 123 |
Fudge | 213 | 123 |
Fudge | 213 | 123 |
Fudge | 213 | 123 |
Fudge | 213 | 123 |
Peanut | 213 | 512 |
Peanut | 213 | 512 |
Peanut | 213 | 512 |
Peanut | 213 | 512 |
Peanut | 213 | 512 |
Peanut | 213 | 512 |
Pistachio | 415 | 242 |
Pistachio | 415 | 242 |
Pistachio | 415 | 242 |
Pistachio | 415 | 242 |
Pistachio | 415 | 242 |
Pistachio | 415 | 242 |
Cherries | 213 | 123 |
Cherries | 213 | 123 |
Cherries | 213 | 123 |
Cherries | 213 | 123 |
Cherries | 213 | 123 |
Cherries | 213 | 123 |
Berry | 213 | 512 |
Berry | 213 | 512 |
Berry | 213 | 512 |
Berry | 213 | 512 |
Berry | 213 | 512 |
Berry | 213 | 512 |
Toffee | 415 | 242 |
Toffee | 415 | 242 |
Toffee | 415 | 242 |
Toffee | 415 | 242 |
Toffee | 415 | 242 |
Toffee | 415 | 242 |
This time I attach the file sales1.doc
Look at your log and post your log.
Also, you posted a bunch of information but didn't clarify what you're asking in this post, since your original question has answers.
@rk7 wrote:
This is the code I have written
data icecream;
INFILE '/folders/myfolders/data/Sales1.dat';
INPUT flavor $10. location boxessold;
if _N_ = 3 to 8 then output;
end;
RUN;proc print;
run;
This is the output I got
Obs flavor location
Chocolate 213 123 Chocolate 213 123 Chocolate 213 123 Chocolate 213 123 Chocolate 213 123 Chocolate 213 123 Vanilla 213 512 Vanilla 213 512 Vanilla 213 512 Vanilla 213 512 Vanilla 213 512 Vanilla 213 512 Pecan 415 242 Pecan 415 242 Pecan 415 242 Pecan 415 242 Pecan 415 242 Pecan 415 242 Choco 2 13 123 Choco 2 13 123 Choco 2 13 123 Choco 2 13 123 Choco 2 13 123 Choco 2 13 123 Strawberry 213 512 Strawberry 213 512 Strawberry 213 512 Strawberry 213 512 Strawberry 213 512 Strawberry 213 512 Coffee 415 242 Coffee 415 242 Coffee 415 242 Coffee 415 242 Coffee 415 242 Coffee 415 242 nuts 213 123 nuts 213 123 nuts 213 123 nuts 213 123 nuts 213 123 nuts 213 123 almonds 213 512 almonds 213 512 almonds 213 512 almonds 213 512 almonds 213 512 almonds 213 512 mint 415 242 mint 415 242 mint 415 242 mint 415 242 mint 415 242 mint 415 242 Fudge 213 123 Fudge 213 123 Fudge 213 123 Fudge 213 123 Fudge 213 123 Fudge 213 123 Peanut 213 512 Peanut 213 512 Peanut 213 512 Peanut 213 512 Peanut 213 512 Peanut 213 512 Pistachio 415 242 Pistachio 415 242 Pistachio 415 242 Pistachio 415 242 Pistachio 415 242 Pistachio 415 242 Cherries 213 123 Cherries 213 123 Cherries 213 123 Cherries 213 123 Cherries 213 123 Cherries 213 123 Berry 213 512 Berry 213 512 Berry 213 512 Berry 213 512 Berry 213 512 Berry 213 512 Toffee 415 242 Toffee 415 242 Toffee 415 242 Toffee 415 242 Toffee 415 242 Toffee 415 242
This time I attach the file sales1.doc
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.