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.

sas-innovate-2024.png

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.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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