BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
pablas
Calcite | Level 5


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

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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. 

View solution in original post

5 REPLIES 5
Astounding
PROC Star

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.

 

pablas
Calcite | Level 5
I wish I had the program but I have got no idea how to read this file in a way that will give me desired output. I know how to read the data line by line or delimited but not when data is delimited and is spread across multiple lines.
Reeza
Super User

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;
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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. 

pablas
Calcite | Level 5
Thanks RW9. It worked.
How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1718 views
  • 2 likes
  • 4 in conversation