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
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;
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;
I thought of that.
Thank you I will give a try!
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!
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
Thank you very much!
Now I understand what it means by "reading in the SAS data set" in my handout.
Thanks!
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!
Get started using SAS Studio to write, run and debug your SAS programs.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.