BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ashna
Obsidian | Level 7

Hello,

 

I need to import an excel file with a where condition saying pull only col a with dateformat .

 

Example : I have a table with 3 columns as follows

Col A               Col B                 Col C

23/11/2018      Cars                  2000

24/10/2018      Buses               4000

Null 

                        test                  600          

 

When I import the above table into sas, I need to pull in data where Col A is non-empty and Col A has only dates.

proc import datafile =filepath 
out=work.input (where=(Not Missing(A) & A=date9.)) 
dbms=xlsx replace;
getnames=No;
run;

Can someone suggest best way to do this.

 

Thanks in advance all the help you provide 🙂

 

1 ACCEPTED SOLUTION

Accepted Solutions
SuryaKiran
Meteorite | Level 14

PROC IMPORT might not be the right way to do this, because it imports data guessing the rows. It may sometimes read date values as character. 

 

First import the data and then using a datastep or proc then modify your dataset. Since you have 'Null' as value I guess SAS will import that field as character. Convert the character to numeric and SAS will identify the format mentioned and gives missing if not valid.

 

proc import datafile =filepath 
out=work.input
dbms=xlsx replace;
getnames=No;
run;


data work.input;
set work.input(rename=(A=A_));
A=input(A_,ddmmyy10.); /* Which are not in ddmmyy format will have missing values */
if not missing(A);
run;
Thanks,
Suryakiran

View solution in original post

2 REPLIES 2
SuryaKiran
Meteorite | Level 14

PROC IMPORT might not be the right way to do this, because it imports data guessing the rows. It may sometimes read date values as character. 

 

First import the data and then using a datastep or proc then modify your dataset. Since you have 'Null' as value I guess SAS will import that field as character. Convert the character to numeric and SAS will identify the format mentioned and gives missing if not valid.

 

proc import datafile =filepath 
out=work.input
dbms=xlsx replace;
getnames=No;
run;


data work.input;
set work.input(rename=(A=A_));
A=input(A_,ddmmyy10.); /* Which are not in ddmmyy format will have missing values */
if not missing(A);
run;
Thanks,
Suryakiran
Reeza
Super User
That may also result in a really messy log....

SAS Innovate 2025: Call for Content

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!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 3012 views
  • 0 likes
  • 3 in conversation