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