BookmarkSubscribeRSS Feed
ScottyEgg
Calcite | Level 5

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 16­90";
		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 
     
AGECOUNTPERCENTAGE 
     
Missing20.01  
48440.03  
61770.08  
78880.37  
81990.68  
     
     
Records with missing age or age out of range of 16-­90
     
Date of BirthDate of MarriageAGEIDCalculated Age
     
21/02/197120/10/2015.144
  21/10/2015.2.
  22/10/2015.3.
17/04/198823/10/2015.427
12/07/198924/10/2015.526

 

FREQUENCIES FOR AGEBS 2012 
     
AGECOUNTPERCENTAGE 
     
Missing20.01  
48440.03  
61770.08  
78880.37  
81990.68  
21/02/197120/10/2015.144
  20/10/2015.2.
  20/10/2015.3.
17/04/198820/10/2015.427
12/07/198920/10/2015.5

26

    

 

4 REPLIES 4
DartRodrigo
Lapis Lazuli | Level 10

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 16­90";
		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,

ScottyEgg
Calcite | Level 5
Made that change and it still seemed to fall over (think as it was using 2 datasets, the first observation in the 2nd dataset wasn't being being treated as "_N_ = 1"
Have now added a step to add row numbering to the datasets and it seems to work!
Probably a little long winded!
arodriguez
Lapis Lazuli | Level 10

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

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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?

 

 

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
  • 4 replies
  • 1068 views
  • 0 likes
  • 4 in conversation