Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

format error - New to SAS

Status
Not open for further replies.

fredong

IS-IT--Management
Sep 19, 2001
332
US
HI ,I am new to SAS and I have a 9.1.3 SAS installed on my workstation. When I executed the script below I ran into error stated "The format $SEX was not found or could not be loaded"'. Below is my script and I have commented with "ERROR HERE !!!". Please advise. Thanks.


libname dummy1 "D:\user\SASTEST\rawdata\TEST";
/* Macro to import the CSV files*/
%macro import(var1,var2);
proc import datafile="&var1"
out=&var2
dbms=csv
replace;
getnames=yes;
run;
%mend;
/* Usage of macro to import the physical csv files into datasets */
%import(D:\user\SASTEST\rawdata\TEST\ivrp.csv,ivrp11);
/* After running the above statement you will find ivrp11 dataset in work library
Work is a default library provided by SAS to store temparory files */

/* This is when a format catalog is created */
proc format library = dummy1;
value $sex
"M"="Male"
"F"="Female"
;
value $AB
0 = "None"
1 = "Stopped"
2 = "Started"
;
run;
/* Specify the library name in this case it will be dummy1 and pass the input dataset in the SET statement */
data dummy1.ivrp (drop = randdt);/* Drop unnecessary columns that are imported */
length study $8.
invsite $6. /* Assigning the length of variable character variable should prefix $ */
invnum 8.
patnum 8.
brthdt 8.
sex $6.
randdt1 8.;
set ivrp11; /* Pass the input dataset name here */
randdt1 = input(randdt,8.); /* Input is used to convert character to numeric */
rename randdt1 = randdt;
invnum = inv;
drop inv;
label study=" TEST Study" /* Label statement is used to set labels for the variables as suggested in the requirement */
invsite="Investigator Site Code"
invnum="Investigator Number"
patnum="Subject ID"
brthdt="Date of Birth"
sex ="Sex"
randdt ="Randomization Date"
randtm="Randomization Time"
;

format randdt brthdt randdtl date9.; /* Applying the default formats */
format sex $sex. ; /*"ERROR HERE !!!". */
run;

/* Incase if we need to add label to a particular dataset use the below syntax*/
proc datasets library = dummy nolist;
modify ivrp (label = 'Subject Data');
run;
quit;
/* Code to convert dataset into transport file */
filename tranfile 'D:\user\SASTEST\rawdata\TEST\ivrp.exp';
proc cport library=dummy1 file=tranfile;
run;
/* Code to convert transport file back to datasets. create a new folder in the library and
try transferring the files over there.. in my case i have created a folder called datasets
in the below statement */
libname dummy1 'D:\user\SASTEST\rawdata\TEST\datasets';
proc cimport library=dummy1 infile=tranfile;
run;

 
You can't have two format statements in the same data step. Just put all your formats in the first format statement. Let me know if this changes the outcome.
Klaz
 
Actually, I resolved my own problem. I have data come in as Female and Male and instead of F and M. So I changed my format to

Female = F
Male = M


and that resolved my problem. Thanks for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top