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

This macro seems to work fine except that my defined vars (school, dob and recnum) are all blank when I open data set ONE in the work library. However, when I submit the PROC PRINT DATA=ONE  statement all of those defined vars show up in the output as I expect. Vars in question are colored red.

 

code:

%MACRO getdata(file=);
DATA a&file;
   INFILE  "G:\Departments\Research\test scores\SAT\&year.\&file..txt" truncover lrecl=2601;
   INPUT  schcode $1-6 cohort_year $59-62 last $113-147 first $148-182 mi $183 sex $184 ethnic $201-202 dobchar $203-212 student_id $234-263 gradyr $635-638 gradmon $640-641 graddate $635-641 testyr $659-662 testmon $664-665 testday $667-668 testdate $659-668 gr $669-670 total_rd 672-675 eb_read_write_sect_rd 676-678 math_sect_rd 679-681 read_rd 682-683 writ_lang_rd 684-685 math_rd 686-689 science_rd 690-691 socstud_rd 692-693 words_context_sub_rd 694-695 evidence_sub_rd 696-697
expr_ideas_sub_rd 698-699 eng_conv_sub_rd 700-701 algebra_sub_rd 702-703 adv_math_sub_rd 704-705 prob_data_analysis_sub_rd 706-707 essay_read_sub_rd 708 essay_analysis_sub_rd 709 essay_writ_sub_rd 710 gpa $1912-1913 yrsart $1933-1935 yrseng $1936-1938 yrslang $1939-1941 yrsmath $1942-1944 yrssci $1945-1947 
yrssoc $1948-1950 activ $2131 sports $2202 @1 line $char2601.;
       *** DEFINE SCHOOL. ***;
   school=put(schcode,actfmt.);
   *** DEFINE DOB. ***;
   dob=input(dobchar,yymmdd10.);  
RUN;
%MEND;
%getdata(file=104268_SAT_20170605_000023);
%getdata(file=104268_SAT_20170620_000024);
 
DATA one;
SET a104268_SAT_20170630_000025
        a104268_SAT_20170605_000023 ;
 
 *** DEFINE RECORD NUMBER. ***;
   recnum=_n_;
run;
proc print data=one;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

You NEED to format that code to make it legible...if we can't read it, it's harder to debug. 

 

It's also not clear what your issue is.

 

View solution in original post

10 REPLIES 10
Reeza
Super User

You NEED to format that code to make it legible...if we can't read it, it's harder to debug. 

 

It's also not clear what your issue is.

 

GreggB
Pyrite | Level 9

The network drive just went down so that's all of the fun for today.

GreggB
Pyrite | Level 9

My issue is that the variables dob, school and recnum are missing for all observations when I open "one" in work.library. When I submit PROC PRINT DATA=ONE the values for dob, school and recnum are there.

 

I need these variables in a subsequent step in order to do some matching. 

Reeza
Super User

Are you sure they're missing for all, or just the first few records?

 

Are all the text files in the same folder and are you importing all files in that folder?

 

 

ballardw
Super User

It may help to show the LOG for the macro reading the data with options mprint; set. Paste the code and any messages into a codebox using the forum {i} menu icon to preserve formatting.

 

Show some values of DOBCHAR where the DOB is missing. (Probably wouldn't hurt to provide a format for DOB like date9 or mmddyy10)

 


@GreggB wrote:

My issue is that the variables dob, school and recnum are missing for all observations when I open "one" in work.library. When I submit PROC PRINT DATA=ONE the values for dob, school and recnum are there.

 

I need these variables in a subsequent step in order to do some matching. 


How do you "open "one" in work.library"? Perhaps you just aren't scrolling far enough to the right to see the columns?

GreggB
Pyrite | Level 9

This was much ado about nothing on my part. I deleted @1 line $char2601.; from the INPUT statement. I think the length of it was obstructing my view of the vars in question.

Astounding
PROC Star

How could the code to create SCHOOL possibly have worked fine?  The formula expresses a character variable (SCHCODE) using a numeric format (ACTFMT.)?

 

We'll need to see the log, and possibly a few examples of data values.

GreggB
Pyrite | Level 9

"fine" was the wrong word. It ran without errors. I'm correcting the schcode format issue.

GreggB
Pyrite | Level 9

This was much ado about nothing on my part. I deleted @1 line $char2601.; from the INPUT statement. I think the length of it was obstructing my view of the vars in question.

ShiroAmada
Lapis Lazuli | Level 10

Looking at this statements....

%MACRO getdata(file=);
DATA a&file;
   INFILE  "G:\Departments\Research\test scores\SAT\&year.\&file..txt" truncover lrecl=2601;
 
#1 You have 2 macro variables YEAR and FILE.
#2. Macro variable is explicit in your macro statement.
#3. The macro YEAR i do not know where you defined this.
 
Better check the log, and locate the WARNING: Apparent symbolic reference YEAR not resolved.

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
  • 10 replies
  • 1157 views
  • 1 like
  • 5 in conversation