DATA Step, Macro, Functions and more

Macro help - defined variables are all missing

Accepted Solution Solved
Reply
Super Contributor
Posts: 279
Accepted Solution

Macro help - defined variables are all missing

[ Edited ]

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;

Accepted Solutions
Solution
‎09-19-2017 08:36 AM
Super User
Posts: 19,822

Re: Macro help - defined variables are all missing

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


All Replies
Solution
‎09-19-2017 08:36 AM
Super User
Posts: 19,822

Re: Macro help - defined variables are all missing

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.

 

Super Contributor
Posts: 279

Re: Macro help - defined variables are all missing

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

Super Contributor
Posts: 279

Re: Macro help - defined variables are all missing

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. 

Super User
Posts: 19,822

Re: Macro help - defined variables are all missing

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?

 

 

Super User
Posts: 11,343

Re: Macro help - defined variables are all missing

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?

Super Contributor
Posts: 279

Re: Macro help - defined variables are all missing

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.

Super User
Posts: 5,513

Re: Macro help - defined variables are all missing

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.

Super Contributor
Posts: 279

Re: Macro help - defined variables are all missing

Posted in reply to Astounding

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

Super Contributor
Posts: 279

Re: Macro help - defined variables are all missing

Posted in reply to Astounding

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.

Frequent Contributor
Posts: 100

Re: Macro help - defined variables are all missing

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.
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 10 replies
  • 122 views
  • 1 like
  • 5 in conversation