Hello
Greetings
How can we export all columns available in data dictionary like Item Label, Item name, Start, Len, data type, item type, Dec , Occ, Zerofill etc , into excel file where each of these comes as a seperate column along with the value sets because analysis asks the data dictionary. When i give a text file by printing command of dictionary, it comes but as a text file.
I tried dictionary macro, it can come in excel, but only variable name and labels are coming, other properties are not coming and also valuesets are coming as separate.
Is there a way of doing it where i can all these in Excel as separate?
Thanks and Regards
MSoni
Exporting entire dictionary in Excel as separate columns
-
- Posts: 1853
- Joined: December 5th, 2011, 11:27 pm
- Location: Washington, DC
Re: Exporting entire dictionary in Excel as separate columns
There is no way to do this directly using CSPro. If you want to automate this process, you will have to parse the dictionary .dcf file yourself and output the data you are interested in.
For example, here is a shell of a JavaScript program that writes out some information about a dictionary. The dictionary must be a CSPro 8.0+ dictionary file, specified in JSON format. You could extend this to include all of the information that interests you. This program can be run in CSCode.
For example, here is a shell of a JavaScript program that writes out some information about a dictionary. The dictionary must be a CSPro 8.0+ dictionary file, specified in JSON format. You could extend this to include all of the information that interests you. This program can be run in CSCode.
// this array will contain the CSV output which we can open in Excel
var csvOutput = [
"Name,Length,Zero Fill"
];
// helper functions
function boolToYN(value) {
return value ? "Yes" : "No";
}
// this function will add the item information to the output;
// a proper implementation of this would properly escape text for CSV so that commas in labels would be handled properly
function processItem(item) {
csvOutput.push(
item.name
+ "," + item.length
+ "," + boolToYN(item.zeroFill)
);
}
// read and parse the dictionary (in CSPro 8.0+ JSON format)
const dictionaryJson = CS.File.readText({
path: "Census Dictionary.dcf"
});
const dictionary = JSON.parse(dictionaryJson);
// iterate through the levels and records, processing each item
dictionary.levels.forEach(level => {
level.ids.items.forEach(idItem => {
processItem(idItem);
});
level.records.forEach(record => {
record.items.forEach(item => {
processItem(item);
});
});
});
// write the CSV to disk
CS.File.writeLines({
path: "Census Dictionary Item Data.csv",
lines: csvOutput
});
var csvOutput = [
"Name,Length,Zero Fill"
];
// helper functions
function boolToYN(value) {
return value ? "Yes" : "No";
}
// this function will add the item information to the output;
// a proper implementation of this would properly escape text for CSV so that commas in labels would be handled properly
function processItem(item) {
csvOutput.push(
item.name
+ "," + item.length
+ "," + boolToYN(item.zeroFill)
);
}
// read and parse the dictionary (in CSPro 8.0+ JSON format)
const dictionaryJson = CS.File.readText({
path: "Census Dictionary.dcf"
});
const dictionary = JSON.parse(dictionaryJson);
// iterate through the levels and records, processing each item
dictionary.levels.forEach(level => {
level.ids.items.forEach(idItem => {
processItem(idItem);
});
level.records.forEach(record => {
record.items.forEach(item => {
processItem(item);
});
});
});
// write the CSV to disk
CS.File.writeLines({
path: "Census Dictionary Item Data.csv",
lines: csvOutput
});
Re: Exporting entire dictionary in Excel as separate columns
Thank you sir for your reply.
Looks this solution not easy. I was thinking any other alternate, or may be sometime in coming version.
Thanks again and Warm regards
MSoni
Looks this solution not easy. I was thinking any other alternate, or may be sometime in coming version.
Thanks again and Warm regards
MSoni