BookmarkSubscribeRSS Feed
rk7
Obsidian | Level 7 rk7
Obsidian | Level 7

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.

11 REPLIES 11
novinosrin
Tourmaline | Level 20

 

 

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;

 

 

 

rk7
Obsidian | Level 7 rk7
Obsidian | Level 7

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.

Reeza
Super User

@rk7 That was @novinosrin answer to you yesterday. Marking your own answer as correct isn't appropriate in this situation.

 

rk7
Obsidian | Level 7 rk7
Obsidian | Level 7

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

 

Reeza
Super User

Nope, fair enough. Thanks for clarifying 🙂

novinosrin
Tourmaline | Level 20

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

rk7
Obsidian | Level 7 rk7
Obsidian | Level 7

what a humble answer. loved it. It will remain an unanswered question

rk7
Obsidian | Level 7 rk7
Obsidian | Level 7
It asks me to accept one of the following as answer. so I select the answer
Reeza
Super User

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.


 

rk7
Obsidian | Level 7 rk7
Obsidian | Level 7

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 

Chocolate213123
Chocolate213123
Chocolate213123
Chocolate213123
Chocolate213123
Chocolate213123
Vanilla213512
Vanilla213512
Vanilla213512
Vanilla213512
Vanilla213512
Vanilla213512
Pecan415242
Pecan415242
Pecan415242
Pecan415242
Pecan415242
Pecan415242
Choco 213123
Choco 213123
Choco 213123
Choco 213123
Choco 213123
Choco 213123
Strawberry213512
Strawberry213512
Strawberry213512
Strawberry213512
Strawberry213512
Strawberry213512
Coffee415242
Coffee415242
Coffee415242
Coffee415242
Coffee415242
Coffee415242
nuts213123
nuts213123
nuts213123
nuts213123
nuts213123
nuts213123
almonds213512
almonds213512
almonds213512
almonds213512
almonds213512
almonds213512
mint415242
mint415242
mint415242
mint415242
mint415242
mint415242
Fudge213123
Fudge213123
Fudge213123
Fudge213123
Fudge213123
Fudge213123
Peanut213512
Peanut213512
Peanut213512
Peanut213512
Peanut213512
Peanut213512
Pistachio415242
Pistachio415242
Pistachio415242
Pistachio415242
Pistachio415242
Pistachio415242
Cherries213123
Cherries213123
Cherries213123
Cherries213123
Cherries213123
Cherries213123
Berry213512
Berry213512
Berry213512
Berry213512
Berry213512
Berry213512
Toffee415242
Toffee415242
Toffee415242
Toffee415242
Toffee415242
Toffee415242

 

This time I attach the file sales1.doc

Reeza
Super User

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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 11 replies
  • 5611 views
  • 6 likes
  • 3 in conversation