Hi everyone.
I have catalog contains 5 variables....AEACN,AETERM,AESTDY,AEBODSYS,AESEV and its description
So Im trying to create dataset from catalog should contain values of 5 variables. when I run below program it gives only AEACN value.so my doubt is instead of giving one entry name what command should we use for getting all desciptions of varibles to a new dataset. Can anyone please help me out.
filename mycat catalog "mine.one.AEACN.SOURCE";
data aeacn;
infile mycat end=eof length=len;
input @1 Description $varying32767. len;
run;
So can I use dataset name as entryname insteadd of AEACN
A catalog does NOT contain variables, datasets contain variables.
Catalogs contain entries of different types (source, format, macro, to name a few).
In your code, you are addressing a single entry of type SOURCE, and try to read it as a text file.
What do you intend to do with a dataset containing code in a character variable?
Please describe your intentions more clearly.
Why the heck are you using source entries in catalogs?
Anyway just use the FILEVAR= option on the INFILE statement to control which member you want to read from the catalog.
First let's make some SOURCE entries in a catalog to have an example to work with.
data _null_;
length memname $32 catalog $200 ;
do memname='AEACN','AETERM','AESTDY' ;
catalog=cats('work.somecat.',memname,'.SOURCE');
file mycat catalog filevar=catalog ;
put memname= ;
end;
run;
Now we can use the same DO loop (or an input dataset if you want) to read all of those entries.
data all;
length memname $32 catalog $200 ;
do memname='AEACN','AETERM','AESTDY' ;
catalog=cats('work.somecat.',memname,'.SOURCE');
infile mycat catalog filevar=catalog length=len end=eof;
do row=1 by 1 while(not eof);
input @1 Description $varying32767. len;
output;
end;
end;
stop;
run;
Resullt:
Obs memname row Description 1 AEACN 1 memname=AEACN 2 AETERM 1 memname=AETERM 3 AESTDY 1 memname=AESTDY
You can query DICTIONARY.CATALOGS (or SASHELP.VCATALG) to get the list of the source objects in a particular catalog.
So now you program can look something like this:
data all;
set sashelp.vcatalg;
where libname='WORK' and memname='SOMECAT' and objtype='SOURCE';
length name $132 ;
name = catx('.',libname,memname,objname,objtype);
infile src catalog filevar=name end=eof;
do line=1 by 1 while(not eof);
input;
description=_infile_;
output;
end;
run;
@sasuser123123 wrote:
#Tom But my expected result is not like that. In description it should have corresponding value of AEACN like
DESCRIPTION
Other action taken
How could I possibly re-create the contents of the binary SAS catalogs on your computer with an example program?
Are you sure you actually have SOURCE catalog entries that you want to read? Your expected output just looks like a variable label, which is not something that would normally be stored in a source catalog. Instead you could just get that from running proc content on the dataset that contains the AEACN variable.
@sasuser123123 wrote:
No actually it's not variable label it's variable (description) value present in catalog
So run the code I posted on your catalog(s) and see what it reads. If it does not look right then just open SAS's Display Manager and look at the source entries yourself and see what is in them.
You seem to have run the code I posted without adapting it to your situation. Including running the data step I had to CREATE some example SOURCE catalogs entries.
Modify the step I posted that READS from the catalog entries so that points to your LIBNAME and MEMNAME, not the catalog that my little example data step created.
The description of a catalog entry is stored in column objdesc of sashelp.vcatalg. To set it, you need to use PROC CATALOG (MODIFY statement).
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.