I have data in the .txt file as:
VALUE ADM_LN2G
1 = 'ENGLISH'
2 = 'FRENCH'
3 = 'ARABIC'
4 = 'CHINESE'
5 = 'CREE'
6 = 'GERMAN'
7 = 'GREEK'
;
VALUE ADM_LNG
24 = 'INUKTITUT'
90 = 'OTHER'
96 = 'NOT APPLICABLE'
97 = 'DON''T KNOW'
98 = 'REFUSAL'
99 = 'NOT STATED'
;
.
.
.
I want to separate out each value in different dataset.
Output expected:
Dataset 1 : ADM_LN2G
VALUE ADM_LN2G
1 = 'ENGLISH'
2 = 'FRENCH'
3 = 'ARABIC'
4 = 'CHINESE'
5 = 'CREE'
6 = 'GERMAN'
7 = 'GREEK'
;
Dataset 2: ADM_LNG
VALUE ADM_LNG
24 = 'INUKTITUT'
90 = 'OTHER'
96 = 'NOT APPLICABLE'
97 = 'DON''T KNOW'
98 = 'REFUSAL'
99 = 'NOT STATED'
;
etc..
For every VALUE there is ";" at the end.
Please help.
Thanks in advance!!
That looks like a proc format text file your readin in, yes? If so why not just create the format catalog with the code and create a dataset from that, so:
%include "<your_file>.sas"; /* The above should create a format catalog then */ proc format library=<library> cntlout=<library>.<dataset>; run;
What this does is read the text file as a proc format, which will create a format catalog - in work lib if not supplied. From that use proc format and cntlout to create a dataset of the values.
There is a ";" as part of the text file. Maybe that's where it's coming from.
If you would like someone to fix your program, you will have to actually show your program.
I think you're misunderstanding. You're not supposed to read that file, it's a program that creates the format. You need to run the program.
If there's no proc format at the top of the file add it and run the code.
proc format;
VALUE ADM_LN2G
1 = 'ENGLISH'
2 = 'FRENCH'
3 = 'ARABIC'
4 = 'CHINESE'
5 = 'CREE'
6 = 'GERMAN'
7 = 'GREEK'
;
VALUE ADM_LNG
24 = 'INUKTITUT'
90 = 'OTHER'
96 = 'NOT APPLICABLE'
97 = 'DON''T KNOW'
98 = 'REFUSAL'
99 = 'NOT STATED'
;
run;
That looks like a proc format text file your readin in, yes? If so why not just create the format catalog with the code and create a dataset from that, so:
%include "<your_file>.sas"; /* The above should create a format catalog then */ proc format library=<library> cntlout=<library>.<dataset>; run;
What this does is read the text file as a proc format, which will create a format catalog - in work lib if not supplied. From that use proc format and cntlout to create a dataset of the values.
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.