- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
/*Import XX.xpt file*/
libname xptfile xport 'path\XX.xpt';
libname sasfile 'destination path';
proc copy inlib=xptfile outlib=sasfile;
run;
proc copy inlib=xptfile outlib=sasfile;
run;
In the above code, the sasfile is created but not able to successfully open the file to check the content. Kindly help for any additional or deletion of syntax
To check and store the created dataset in above code had created below code but still not working but the plus point is that am able to check the table properties.
/*Storing in AA dataset*/
libname trial 'Destination path';
data trial.demo;
set xx;
run;
After writing above code following error is coming
The format BTPU11_ was not found or could not be loaded
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@Tejaswini3 wrote:
When I open those individual dataset, am able to see the variable.
May be because of format issue, its not able to recognise
Your explanations are too brief to really understand what your issue is. You posted code that could successfully convert two XPT files into datasets. And convert the FORMATS dataset into a format catalog in the WORK directory. But then you also show code that is trying to reference some potentially unrelated datasets.
If you can see the variable then tells us how it is defined. What is the NAME of the variable? The TYPE? The storage LENGTH? Does it have a FORMAT attached? If so what format? Does it have a LABEL attached? If so what is the label?
The DMG dataset you created from the dmg.xpt file only has 14 variables. Just run PROC CONTENTS and show us the output from that. It should list each variable with its position number, name, type , length and if attached any format or label. It might also show if it has an informat attached, but for an existing dataset an informat does not really play much of a role.
Remember when pasting text like code or lines from the SAS log to paste them into the pop-up boxes that the forum editor will open when you click on the Insert Code or Insert SAS code button. That will prevent the forum from re-flowing the text as if it were paragraphs.
So here is basic code to convert DMG and FORMATS into a dataset and a catalog in that 04utility folder in your code.
options nofmterr;
%let path=D:\SAS\Project\Project 3- Interating Data for PKAnalysis\Project 3- Interating Data for PKAnalysis\Work;
libname utility "&path\04utility";
libname xptlib1 xport "&path\02data_raw\dmg.xpt";
libname xptlib2 xport "&path\02data_raw\formats.xpt";
proc format fmtlib cntlin=xptlib2.formats lib=utility ;
run;
proc copy inlib=xptlib1 outlib=utility;
run;
To tell SAS to use that formats catalog you can add it to the search path used by using the APPEND option like this:
options append=(fmtsearch=(utility.formats));
Now you can run code to look at the DMG dataset. Since it is small I would would just print the whole thing. I would print it twice, once using the formats and once without the formats.
proc print data=utility.dmg;
title 'formatted values';
run;
proc print data=utility.dmg;
format _all_ ;
title 'unformatted values';
run;
title;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The dataset uses a custom format.
To make the dataset usable, use
options nofmterr;
To recreate the format, request the PROC FORMAT code from the source.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thankyou for the reply.
How to recreate the format? I have format file in .xpt and as dataset.
libname library 'path';
options fmtsearch=(library.format_raw);
proc format cntlin=library.format_raw;
quit;
data PKDMG;
merge bapk (in=a) DMG (in=b);
keep country sex DOB1D race;
format formats.;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@Tejaswini3 wrote:
Thankyou for the reply.
How to recreate the format? I have format file in .xpt and as dataset.
libname library 'path';
options fmtsearch=(library.format_raw);
proc format cntlin=library.format_raw;
quit;data PKDMG;
merge bapk (in=a) DMG (in=b);
keep country sex DOB1D race;
format formats.;
run;
That is not going to work.
First told it to use a CATALOG named FORMAT_RAW in the directory pointed to by LIBRARY as the place to look for formats. Does that CATALOG actually exist?
Then you told it to use a DATASET named FORMAT_RAW as input to PROC FORMAT to create a CATALOG named WORK.FORMATS. Does that DATASET actually exist?
If you have a dataset named FORMAT_RAW you can use it in one of two ways.
Leave the FMTSEARCH option alone so that it will search the WORK.FORMATS catalog your PROC FORMAT step is creating.
Or use the LIB=LIBRARY.FORMAT_RAW option on the PROC FORMAT statement to tell it where to write the catalog so that your modified FMTSEARCH option setting will search it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thankyou sir for the reply. But still i am facing issue in it.
Can you please help me with draft code.
It would be a great help. I want to use the format sasfile in a data step
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@Tejaswini3 wrote:
Thankyou sir for the reply. But still i am facing issue in it.
Can you please help me with draft code.
It would be a great help. I want to use the format sasfile in a data step
What type of "format sasfile" do you have?
If you have XPT file that contains SAS V5 transport files so that your original code that use the XPORT libname engine works then the only types of file that can contain are SAS datasets.
How many dataset where in the XPT file? The SAS log from your PROC COPY step should show you the names of the files that were copied out of the XPT file. If the PROC COPY step generated an error reading from the XPT file then you do not have a SAS V5 transport file. If you have a file created by PROC CPORT then it could contain a format catalog. You would need to use PROC CIMPORT to read such a file.
If one the SAS dataset has a name that makes your think it might have the format definitions then take a look at what it has in it it. Run PROC CONTENTS to see what the variables are. Run PROC PRINT or a simple data step like below to see what some of the values look like.
Say you have a dataset named SASFILE.FORMAT_NEW. To look at some of the values you could run this code to dump the values of the variables in the first three observations to the SAS log.
data _null_;
set sasfile.format_new (obs=3);
put (_all_) (=/);
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Convert .xpt file to sas dataset format
libname xptfile xport 'path\formats.xpt';
libname sasfile 'path';
proc copy inlib=xptfile outlib=sasfile;
options nofmterr;
run;
Dataset code where want to read the file with the help of formats
data trial;
merge Y (in=a) X (in=b);
keep country sex DOB1D race;
format country CHIP11. sex SEX11_. DOB1D ETH11_. race RCE51_.;
run;
Here in this file, the format CHIP11. and others are from formats file. Still not able to read it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Please post the SAS log from running this step so we can tell whether the LIBNAME and PROC COPY step worked. And if they did what datasets were found in the XPT file.
options nofmterr;
libname xptfile xport 'path\formats.xpt';
libname sasfile 'path';
proc copy inlib=xptfile outlib=sasfile;
run;
Copy the lines from the SAS log and paste into the window that pops up when you push the Insert Code icon (The icon looks like the characters < / > ). You might want to remove the actual physical path from the log rather than post it on-line. But make sure to do it in the pop-up window so that the formatting of the lines from the SAS log is preserved.
If the PROC COPY step actually created a dataset then also run PROC CONTENTS on the dataset it created so we can see if it looks like a dataset that could actually define your formats.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Using proc content code able to see the content.
The only doubt is how to use this format datafile while reading a different dataset
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@Tejaswini3 wrote:
I am able to convert the format file into .sas7bdat.
Using proc content code able to see the content.
The only doubt is how to use this format datafile while reading a different dataset
So you have a dataset that you think describes the formats? What does it look like? Does it look like the dataset that PROC FORMAT creates with CNTLOUT= option? If not could you convert it into one? The key things you need to define a format are the name for the format, the raw or uncoded value and the display or coded value. FMTNAME, START, LABEL are the variable names you will need for that informat. Remember that a format name cannot end with a digit.
Do the values mentioned in the format definition look like the values in the dataset variables that are supposed to use those formats? You can use NOFMTERR option to allow you to look a the dataset that has a permanently attached format that your current session cannot find. You can use a FORMAT statement that lists variable(s) without any format specification after them to remove a permanently attached format so that you can print the actual values.
If you have the information to define the formats then you can use PROC FORMAT to create a format catalog from the data. Use the FMTSEARCH option to tell SAS to look for format there. Then use the formats with the actual data you have.
To get detailed help you need to provide detail information. Show the lines from your SAS log of the code you tried. Show the content information of the format dataset. Show some of the values. Show the content information of the dataset that needs to use the format. Show some of the values.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thankyou sir.
Kindly find below screenshot of format file in .sas7bdat format. I want to use this format file in some other dataset. the resulting dataset which have usage of different sas data process. Kindly help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hard to tell since you posted a photograph of something that appears to be using the LABEL as the column header instead of the NAME of the variable. But it looks like that is valid for use with PROC FORMAT. Try it.
So if you converted that XPT file into the WORK.FORMATS dataset you could run this code to create the formats in the WORK.FORMATS catalogs.
proc format cntlin=formats;
run;
Then you could try running PROC FREQ on one of your variables that is using that DART11_ format that it looks like your dataset contains. So if you have a dataset name HAVE with a variable named DART11 you might use
proc freq data=HAVE;
tables dart11 ;
format dart11 dart11_. ;
run;
To see the raw values remove the format from the variable. So run code like this and compare to the previous table.
proc freq data=HAVE;
tables dart11 ;
format dart11 ;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
merge Y (in=a) X (in=b);
keep country sex DOB1D race;
format country sex DOB1D race;
run;
By writing this code I am able to merge the dataset. But the problem is if I want to perform some other process on trial and in log 'xxx format cannot be identified'.
Kindly help
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@Tejaswini3 wrote:
Thankyou sir.
Kindly find below screenshot of format file in .sas7bdat format. I want to use this format file in some other dataset. the resulting dataset which have usage of different sas data process. Kindly help.
Run
proc format cntlin=dataset;
run;
where dataset is this dataset you show here, and then try to open/use your other dataset(s) again.