Hi! Trying something a little different from what I normally do with data nulls for our CSV outputs. Trying to output 2 datasets in one output. Its kind of works but isn't inserting the break or secondary headings I want. Any help most welcome.
Heres the code :-
DATA _NULL_;
SET work.agebs (IN = FREQ)
work.agebsout (IN = OUTP) END = last;
FILE &csvfile1 linesize=1000 lrecl=1000;
IF FREQ THEN DO;
IF _n_ = 1 THEN
DO ;
PUT "FREQUENCIES FOR AGEBS,,,&year";
PUT ",,";
PUT "AGE,COUNT,PERCENTAGE";
PUT ",,";
END;
IF AGE = . THEN PUT
'Missing,'
COUNT ','
PERCENT 7.2;
ELSE PUT
AGE ','
COUNT ','
PERCENT 7.2;
END;
IF OUTP THEN DO;
IF row = 1 THEN
DO ;
PUT "Records with missing age or age out of range of 1690";
PUT ",,";
PUT "Date of Birth,Date Now,Age,ID,Calculated Age,";
PUT ",,";
END;
PUT DOB ','
DONOW ','
AGE ','
ID ','
calcage;
END;
RUN;
1st is what I want out (appended but enough to give an idea, Ignore numbers all been changed just illustrative)
2nd is what I currently get out
FREQUENCIES FOR AGE | 2012 | |||
AGE | COUNT | PERCENTAGE | ||
Missing | 2 | 0.01 | ||
48 | 44 | 0.03 | ||
61 | 77 | 0.08 | ||
78 | 88 | 0.37 | ||
81 | 99 | 0.68 | ||
Records with missing age or age out of range of 16-90 | ||||
Date of Birth | Date of Marriage | AGE | ID | Calculated Age |
21/02/1971 | 20/10/2015 | . | 1 | 44 |
21/10/2015 | . | 2 | . | |
22/10/2015 | . | 3 | . | |
17/04/1988 | 23/10/2015 | . | 4 | 27 |
12/07/1989 | 24/10/2015 | . | 5 | 26 |
FREQUENCIES FOR AGEBS | 2012 | |||
AGE | COUNT | PERCENTAGE | ||
Missing | 2 | 0.01 | ||
48 | 44 | 0.03 | ||
61 | 77 | 0.08 | ||
78 | 88 | 0.37 | ||
81 | 99 | 0.68 | ||
21/02/1971 | 20/10/2015 | . | 1 | 44 |
20/10/2015 | . | 2 | . | |
20/10/2015 | . | 3 | . | |
17/04/1988 | 20/10/2015 | . | 4 | 27 |
12/07/1989 | 20/10/2015 | . | 5 | 26 |
|
Hi mate,
I think if you change the second part of your code to the following, it will work:
IF _n_ = 1 THEN
DO ;
PUT "Records with missing age or age out of range of 1690";
PUT ",,";
PUT "Date of Birth,Date Now,Age,ID,Calculated Age,";
PUT ",,";
END;
PUT DOB ','
DONOW ','
AGE ','
ID ','
calcage;
Change the row = to _n_ =
Att,
Hi ScottEgg,
you have used
IF ROW=1 THEN DO
Your input dataset have ROW variable? If not, you should do that your second dataset have ROW=_N_; Doing that, you will have a kind of '_N_' for the second dataset
Personally I think your over complicating things for yourself. FIrst work on getting a dataset which looks as you want it, then output it. There is no reason to do it all in one step. Secondly, your output file is not a CSV, it is a format you have come up with yourself, maybe based in some way on CSV, but its not. CSV file has one row of header labels separated by comma, then and until the EOF data for those columns separated by commas. You have two separate files in one. If you require output, then go directly to RTF or PDF and put each on separate pages, for data, keep the data, don't try to keep the output in some form of data?
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.