BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jc3992
Pyrite | Level 9
 
 data style; 
 infile '/folders/myfolders/Artists.dat'; 
 input Name $ 1-21 Genre $ 23-40 Origin $42; 
 run; 
  
 data style; 
 if Genre = 'Impressionism' ; 
 run; 
 proc print data=style; 
 run;

Hello everyone,

I used this code to try to print out only when "Genre= Impressionism"and the LOG is as below.

I wonder if anyone can help me modifying this to make it work out?

I did not see what has went wrong.

Thank you:)

 

 1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 72         
 73          data style;
 74          infile '/folders/myfolders/Artists.dat';
 75          input Name $ 1-21 Genre $ 23-40 Origin $42;
 76          run;
 
 NOTE: The infile '/folders/myfolders/Artists.dat' is:
       Filename=/folders/myfolders/Artists.dat,
       Owner Name=sasdemo,Group Name=sas,
       Access Permission=-rw-rw-r--,
       Last Modified=09Feb2018:21:01:38,
       File Size (bytes)=306
 
 NOTE: 7 records were read from the infile '/folders/myfolders/Artists.dat'.
       The minimum record length was 42.
       The maximum record length was 42.
 NOTE: The data set WORK.STYLE has 7 observations and 3 variables.
 NOTE: DATA statement used (Total process time):
       real time           0.01 seconds
       cpu time            0.01 seconds
       
 
 77         
 78          data style;
 79          if Genre = 'Impressionism' ;
 80          run;
 
 NOTE: Variable Genre is uninitialized.
 NOTE: The data set WORK.STYLE has 0 observations and 1 variables.
 NOTE: DATA statement used (Total process time):
       real time           0.00 seconds
       cpu time            0.01 seconds
       
 
 81          proc print data=style;
 82          run;
 
 NOTE: No observations in data set WORK.STYLE.
 NOTE: PROCEDURE PRINT used (Total process time):
       real time           0.00 seconds
       cpu time            0.00 seconds
       
 
 83         
 84         
 85         OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 98         
1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

You are missing set statement to read the input dataset

 

 data style; 
 infile '/folders/myfolders/Artists.dat'; 
 input Name $ 1-21 Genre $ 23-40 Origin $42; 
 run; 
  
 data style; 
set style;/*you missed this*/ if Genre = 'Impressionism' ; run; proc print data=style; run;

View solution in original post

5 REPLIES 5
novinosrin
Tourmaline | Level 20

You are missing set statement to read the input dataset

 

 data style; 
 infile '/folders/myfolders/Artists.dat'; 
 input Name $ 1-21 Genre $ 23-40 Origin $42; 
 run; 
  
 data style; 
set style;/*you missed this*/ if Genre = 'Impressionism' ; run; proc print data=style; run;
jc3992
Pyrite | Level 9

I thought of that.

Thank you I will give a try!

jc3992
Pyrite | Level 9

It works!

Thank you very much!

 

May I understand why the "Set" command is needed here?

I thought I missed "then do;"

 

Thank you very much!

novinosrin
Tourmaline | Level 20

In your 1st step, you read a raw(external data) data to create a dataset called style. In your 2nd step, your objective is/was to filter the dataset style using if or where. So, you need to use/read/ that dataset in some way. The set statement basically reads records of the style dataset and your if filters it and the data statement creates a new dataset style yet again

jc3992
Pyrite | Level 9

Thank you very much!

Now I understand what it means by "reading in the SAS data set" in my handout.

Thanks!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 5 replies
  • 1345 views
  • 2 likes
  • 2 in conversation