Learning SAS? Welcome to the exclusive online community for all SAS learners.

Proc Format

Reply
Occasional Contributor
Posts: 12

Proc Format

Hello I am new to SAS and I am stuck on Proc Format. 

 

Whenever I run the code in bold below I get the following error message “Unable to get ‘trim’ of undefined or null reference.”  I don't know what this means, but the resulting output is supposed to be another variable created in the data called "hichol."  I am using SAS Studio for a course that I am taking. 

 

The programmer in my office ran the code on our licensed SAS software and it worked just fine.  Can someone provide some assistance? 

 

 

 

libname _class "/courses/dd00a3e5ba27fe300/c_8798/saslib/classdata" access=readonly;

 

data frm; set _class.frmgham;run;

 

proc format;

value chol

 

data frm2;  set frm;

hichol=put(totalchol,chol.);

run;

 

 

 

Super User
Posts: 17,912

Re: Proc Format

I don't know if the editor trimmed your code, but I don't see any code in your proc format. 

 

proc format;
value chol

Probably a copy paste fail somewhere?

 

You should have a list of values and how the map to a description or different value. 

 

 

Occasional Contributor
Posts: 12

Re: Proc Format

Hello I am new to SAS and I am stuck on Proc Format. 

 

Whenever I run the code in bold below I get the following error message “Unable to get ‘trim’ of undefined or null reference.”  I don't know what this means, but the resulting output is supposed to be another variable created in the data called "hichol."  I am using SAS Studio for a course that I am taking.  The full code is below.  Any assistance would be greatly appreciated. 

 

 

libname _class "/courses/dd00a3e5ba27fe300/c_8798/saslib/classdata" access=readonly;

data frm; set _class.frmgham;run;

proc format;
value hichol
0-200="low chol"
201-250="ok chol"
251-high="hi chol"
.=" "
other="na"
;

data frm2;  set frm;
hichol=put(totalchol,chol.);
run;

Super User
Posts: 10,538

Re: Proc Format

hichol=put(totalchol,chol.);

Does not reference the format created, hichol.

Occasional Contributor
Posts: 12

Re: Proc Format

I tried it as "value chol" and it still would not work.   

Super User
Posts: 10,538

Re: Proc Format

I can't replicate that error in base SAS. Can you post the log where you ran the proc format and the datastep?

 

I would try specifying a length for the HICHOL variable before use though. A variable without a specific length sometimes behaves in unexpected ways.

 

data frm2;
   set frm;
   length hichol $ 8;
   hichol=put(totalchol,chol.);
run;
Occasional Contributor
Posts: 12

Re: Proc Format

Thanks,

 

I tried specifying the length, but got the same error.  Here is the log of the results:

 

 

1        OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;

 55        

 56         data frm2;  set frm;

 57         length hichol $ 8;

 58         hichol=put(totchol,chol.);

 59         run;

 

 NOTE: There were 11627 observations read from the data set WORK.FRM.

 NOTE: The data set WORK.FRM2 has 11627 observations and 40 variables.

 NOTE: DATA statement used (Total process time):

       real time           0.01 seconds

       user cpu time       0.01 seconds

       system cpu time     0.01 seconds

       memory              3471.93k

       OS Memory           32168.00k

       Timestamp           07/28/2016 04:54:28 PM

       Step Count                        48  Switch Count  36

       Page Faults                       0

       Page Reclaims                    928

       Page Swaps                        0

       Voluntary Context Switches        93

       Involuntary Context Switches      0

       Block Input Operations            0

       Block Output Operations           7432

      

 

 60        

 61         OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;

 73        

 

Super User
Posts: 10,538

Re: Proc Format

I don't see the error message you said you were getting.

 

Is that occuring in a later step or procedure?

Occasional Contributor
Posts: 12

Re: Proc Format

No, it only occurs with this section of code: hichol=put(totchol,chol.);

 

The programmer in my office ran this entire code with Base SAS and had no problems.  I really think it is an issue with SAS Studio.  No one can replicate the error not even the instructor for the course I am taking, but the error appears every time I try to run this portion of the code.

Super User
Posts: 10,538

Re: Proc Format

Is the output of the dataset as expected for the values of your HICHOL variable?

If so put it in the "mysteries of computers" box.

 

Did this code by any chance get copied and pasted from a web site or formatted document such as Word or PDF?

If that is the case you might try re-typing it directly into the editor and deleting the existing. It is't a very long line after all. Sometimes things are ending up in code files that are not valid but don't appear. I get something like that about once every two weeks from code posted on this site. Code I know should work but throws errors. Retyping fixes many of them.

Occasional Contributor
Posts: 12

Re: Proc Format

Yes the output of the dataset as expected for the values is the HICHOL variable. 

 

I will try retyping the code again. 

Occasional Contributor
Posts: 12

Re: Proc Format

Okay,

 

So I tried the code again and it still does not work.  I even retyped the code.  There seems to be an issue with SAS Studio.  The problem only occurs when I try to run this section of code: hichol=put(totchol,chol.);

 

I continue to get an error message.  Any suggestions?  If it works on Base SAS why won't it run in SAS Studio?

 

The code is below.  I tried to attach the data file but it would not upload.   

 

libname _class "/courses/dd00a3e5ba27fe300/c_8798/saslib/classdata" access=readonly;

data frm; set _class.frmgham; run;

proc format;
value chol
0-200="low chol"
201-250="OK chol"
251-high="hi chol"
;
data frm2; set frm;
hichol=put(totchol,chol.);
run;

Super User
Posts: 17,912

Re: Proc Format

Post your full log please from the full code.

Your other log above where you say there's an error, doesn't show an error that I can see. 

Occasional Contributor
Posts: 12

Re: Proc Format

 

The code shows totchol as the variable and hichol is shown on the contents below, however the type of variable is listed as a character, while all of the others are numbers.  Could this be the issue?  If so, how to I fix it?

 

libname _class "/courses/dd00a3e5ba27fe300/c_8798/saslib/classdata" access=readonly;

data frm; set _class.frmgham;run;

proc format;
value chol
0-200="low chol"
201-250="ok chol"
251-high="hi chol"
.=" "
other="na"
;

Proc contents;
data frm2;  set frm;
hichol=put(totchol,chol.);
run;

 

 

 

 

 

The CONTENTS Procedure

The CONTENTS Procedure WORK.FRM2 Attributes Data Set Name Observations Member Type Variables Engine Indexes Created Observation Length Last Modified Deleted Observations Protection Compressed Data Set Type Sorted Label   Data Representation   Encoding  

WORK.FRM211627
DATA40
V90
07/29/2016 12:58:38320
07/29/2016 12:58:380
 NO
 NO
  
SOLARIS_X86_64, LINUX_X86_64, ALPHA_TRU64, LINUX_IA64 
utf-8 Unicode (UTF-8) 

Engine/Host Information Engine/Host Dependent Information Data Set Page Size Number of Data Set Pages First Data Page Max Obs per Page Obs in First Data Page Number of Data Set Repairs Filename Release Created Host Created Inode Number Access Permission Owner Name File Size File Size (bytes)

131072
29
1
409
385
0
/saswork/SAS_workFA0800008E0C_odaws04-prod-us/SAS_work6BEF00008E0C_odaws04-prod-us/frm2.sas7bdat
9.0401M3
Linux
12845086
rw-r--r--
lbryant0
4MB
3932160

Variables Alphabetic List of Variables and Attributes # Variable Type Len Label 4 24 27 9 11 8 7 29 23 10 6 13 21 12 25 30 22 26 20 15 14 18 16 17 2 1 28 5 19 31 34 36 37 38 32 33 35 3 39 40

AGENum8Age (years) at examination
ANGINANum8Incident Angina Pectoris
ANYCHDNum8Incident Hosp MI, AP, CI, Fatal CHD
BMINum8Body Mass Index (kr/(M*M)
BPMEDSNum8Anti-hypertensive meds Y/N
CIGPDAYNum8Cigarettes per day
CURSMOKENum8Current Cig Smoker Y/N
CVDNum8Incident Hosp MI or Stroke, Fatal or Non
DEATHNum8Death indicator
DIABETESNum8Diabetic Y/N
DIABPNum8Diastolic BP mmHg
GLUCOSENum8Casual Glucose mg/dL
HDLCNum8HDL Cholesterol mg/dL
HEARTRTENum8Ventricular Rate (beats/min)
HOSPMINum8Incident Hospitalized MI
HYPERTENNum8Incident Hypertension
LDLCNum8LDL Cholesterol mg/dL
MI_FCHDNum8Incident Hosp MI-Fatal CHD
PERIODNum8Examination cycle
PREVAPNum8Prevalent Angina
PREVCHDNum8Prevalent CHD (MI,AP,CI)
PREVHYPNum8Prevalent Hypertension
PREVMINum8Prevalent MI (Hosp,Silent)
PREVSTRKNum8Prevalent Stroke (Infarct,Hem)
RANDIDNum8Random ID
SEXNum5SEX
STROKENum8Incident Stroke Fatal/non-fatal
SYSBPNum8Systolic BP mmHg
TIMENum8Days since Index Exam
TIMEAPNum8Days Baseline-Inc Angina
TIMECHDNum8Days Baseline-Inc Any CHD
TIMECVDNum8Days Baseline-Inc CVD
TIMEDTHNum8Days Baseline-Death
TIMEHYPNum8Days Baseline-Inc Hypertension
TIMEMINum8Days Baseline-Inc Hosp MI
TIMEMIFCNum8Days Baseline-Inc MI-Fatal CHD
TIMESTRKNum8Days Baseline-Inc Stroke
TOTCHOLNum8Serum Cholesterol mg/dL
censorNum8 
hicholChar8 
Super User
Posts: 17,912

Re: Proc Format

Run this code as is, and post the log from all the code. I don't think it will generate an error. Your previous error was only because you referenced the incorrect variable.

 

libname _class "/courses/dd00a3e5ba27fe300/c_8798/saslib/classdata" access=readonly;

data frm; 
set _class.frmgham;
run;

proc format;
value chol
0-200="low chol"
201-250="ok chol"
251-high="hi chol"
.=" "
other="na"
;



data frm2;  
set frm;
hichol=put(totchol,chol.);
run;

proc freq data=frm2;
table hichol;
run;
Ask a Question
Discussion stats
  • 22 replies
  • 667 views
  • 0 likes
  • 4 in conversation