BookmarkSubscribeRSS Feed
scb
Obsidian | Level 7 scb
Obsidian | Level 7

DATA TEST201704;
INPUT ID $;
DATALINES;
110
111
112
113
114
115
116
117
;
RUN;

DATA TEST201703;
INPUT ID $;
DATALINES;
110
111
112
;
RUN;

 

PROC SQL;
CREATE TABLE TESTING AS SELECT *,
CASE WHEN ID IN (SELECT ID FROM TEST201703) THEN 0 ELSE 1 END AS EXIST
FROM TEST201704;
QUIT;

 

The above proc sql codes is working fine.  As the TEST dataset is not available in every period, it could have no data on some period, e.g. 201702.  if I run the below codes, there will be an error message read "ERROR: File WORK.TEST201702.DATA does not exist."

My question is: May i know how to set the EXIST key to 1 in TESTING data if the previous period of TEST data (TEST201702) not available? Thanks. 

 

PROC SQL;
CREATE TABLE TESTING AS SELECT *,
CASE WHEN ID IN (SELECT ID FROM TEST201702) THEN 0 ELSE 1 END AS EXIST
FROM TEST201703;
QUIT;

 

1 REPLY 1
Patrick
Opal | Level 21

You need first to check if the dataset exists and then branch to different code logic based on existence or not.

http://support.sas.com/kb/24/670.html 

 

One way to go could be that you create an empty dataset in case it doesn't exists.

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 620 views
  • 0 likes
  • 2 in conversation