Hello community,
I wanted to ask you if there is a way to read the rows from a csv file if starts with a specific string.
For example in this csv I want just the rows that starts with "2021-01", so the row that starts with 2021-09 will be deleted.
Like this:
data _null_;
file "R:\some_test_file.csv";
put "2021-01-01,1,2,3";
put "2021-01-02,4,5,6";
put "2021-01-03,7,8,9";
put "2021-09-01,1,2,3";
put "2021-09-02,4,5,6";
put "2021-09-03,7,8,9";
run;
filename f "R:\some_test_file.csv";
data want;
infile f dlm=",";
input @;
if "2021-01" =: _infile_;
input date yymmdd10. a b c;
format date date11.;
run;
proc print;
run;
Bart
Like this:
data _null_;
file "R:\some_test_file.csv";
put "2021-01-01,1,2,3";
put "2021-01-02,4,5,6";
put "2021-01-03,7,8,9";
put "2021-09-01,1,2,3";
put "2021-09-02,4,5,6";
put "2021-09-03,7,8,9";
run;
filename f "R:\some_test_file.csv";
data want;
infile f dlm=",";
input @;
if "2021-01" =: _infile_;
input date yymmdd10. a b c;
format date date11.;
run;
proc print;
run;
Bart
Please provide sample data as text and not as screenshot - ideally via a SAS data step that creates the sample data.
data demo;
infile datalines4 truncover dsd dlm=';';
input row_dt :yymmdd10. @;
if put(row_dt,yymmn6.)='202101';
input val :best32. next_var :$10.;
format row_dt date9.;
datalines4;
2021-01-18;111;keep
2021-09-01;34;drop
2021-01-22;111;keep
.;111;keep
;;;;
proc print data=demo;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.