BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi,

I need some info on the limit of length of character Variable used in PROC FORMAT Value statement. I have some data related to Health Risk Appraisal, where questions are very long (to 200 bytes max). I need to map these questions to a question code for each question in PROC FORMAT. Please let me know if any other way to do this other than in if statement in data step statement.

thanks,
5 REPLIES 5
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Explore using PROC FORMAT with CNTLIN= to create your SAS format from a SAS input file. The DOC has all the information you need.

Scott Barry
SBBWorks, Inc.

Recommended Google advanced search arguments, this topic/post:

proc format cntlin site:sas.com

proc format character format site:sas.com
deleted_user
Not applicable
hi Support,

I have checked the documentation, but I am not sure how to refer the lookup value referred to the question in proc format.

I read in all possible questions that I will be getting in the data and assigned a question code for each of the question (which was 250 byte long). I used PROC Format on dataset which had variables.

My code is like this -

data lookup ;
infile inp lrecl = 300 recfm = v delimiter = ',' end = eof dsd truncover ;

length questnin $250.
quesncd $7.
questxtcd $258.
;


input

questnin $
quesncd $
;

questxtcd = Trim(quesncd) || '-' || Trim(questnin) ;

start = questxtcd ;
LABEL = 'KEEP' ;
FMTNAME = '$queskey';

run;

PROC SORT DATA = lookup OUT = FMTOUT NODUPKEY ;
BY start ;

PROC FORMAT CNTLIN=FMTOUT;
run;


So when I read in my raw file - when I refer to CNTLIN format on the raw variable for question we are getting, I am not getting desired output.

Say for example I have a question like this - "HOW MANY HOURS OF SLEEP DO YOU USUALLY GET AT NIGHT?" where I gave QUEST1

So when ever I encounter this question on data, I need to output Quest1 instead of that so long full question. Looks like my reference to PROC Fromat is not working -

HA_QUES_TXT = put(Trim(Left(HA_QUESTION_TEXT)),$QUESKEY.);

HA_QUESTION_TEXT is variable in raw data that I am getting.

Please let me know what else I need to take care to output value "QUEST1".

thanks in Advance,
LG
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
For clarification, this is not SAS Technical Support - that's a different (paid) channel, except maybe the wonderful and thought-provoking Cynthia...

Your SAS code that builds the START variable must match exactly the SAS code that constructs the PUT function argument #1.....they do not appear to be consistent.

So, for self-debugging, have you attempted to analyze the generated format, either with the PROC FORMAT FMTLIB parameter, or better yet, use CNTLOUT= to unload your format and do a PROC PRINT on the SAS-generated file specified on CNTLOUT.

You mention something about "..I need to output Quest1..." but you do not share allof your SAS DATA step code that uses HA_QUES_TXT -- the variable assigned from the PUT function. A match-condition will result in a value of KEEP -- so what do you do then?

Scott Barry
SBBWorks, Inc.
deleted_user
Not applicable
Hi Sbb,

Thanks for response. It gave me some direction on how to approach, but not exactly what I needed.

I thought Arg #1 after lookup to PROC FORMAT will result in the short form of Question. But that's not happening. not sure how to get this resolved.

Any ideas would help me a lot and I appreciate it.

thanks,
LG
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Possibly, if you want SAS to return the short-form (your words) on a "match condition", then you need to assign whatever you expect back with the LABEL variable, not the string "KEEP" which only identifies when you have a "match condition" but provides no relief to save some data back from the format.

Also, with creating your CNTLIN= file, after you output the last observation (on END=EOF with the SET stmt), then you want one additional observation for the OTHER= telling SAS what to return on a no-match condition. The DOC explains this technical application / approach.

Scott Barry
SBBWorks, Inc.

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