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-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!

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
  • 652 views
  • 0 likes
  • 3 in conversation