BookmarkSubscribeRSS Feed
JasonNC
Quartz | Level 8

Hi,

I am creating formats for look up so that i can avoid left joins which help in increasing performance.

For example based on the data i get i want to create formats

DATA TEST;

INPUT CODE $;

DATALINES;

NC

NY

AZ

;

RUN;

%MACRO FMT;

%GLOBAL CNT;

PROC SQL NOPRINT;

SELECT COUNT(*) INTO :CNT FROM TEST

WHERE CODE NE ' ' ;

QUIT;

%IF &CNT > 0 %THEN %DO;

PROC SQL NOPRINT;

CREATE TABLE SPECDESC AS

SELECT CODE AS START,DESC AS LABEL,'$DES' AS FMTNAME

FROM DESCR_TB

WHERE CODE IN (SELECT CODE FROM TEST WHERE CODE NE '' );

QUIT;

PROC FORMAT CNTLIN=SPECDESC;

RUN;

%END;

%MEND;

%FMT;

DATA TEST1;

SET TEST;

IF &CNT > 0 THEN DO;

DESCR=PUT(CODE,$DES.);

END;

ELSE DO;

DESCR=CODE;

END;

RUN;

I am getting an error when i am not having data in test

It is showing that $DES format cannot be found or load.

I want to create formats based on the data.I want to find a work around when there is no data.

2 REPLIES 2
TomKari
Onyx | Level 15

How about after:

PROC FORMAT CNTLIN=SPECDESC;

RUN;

%END;

insert:

%ELSE %DO;

PROC FORMAT;

VALUE $DES;

RUN;

%END;

Tom

Ksharp
Super User

Or add another column to specify the format type.

SELECT CODE AS START,DESC AS LABEL,'DES' AS FMTNAME,'C' AS TYPE

Ksharp

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 2 replies
  • 760 views
  • 0 likes
  • 3 in conversation