Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7865351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:03:42+00:00 2026-06-03T00:03:42+00:00

I am trying to write a SAS script that will simply read in a

  • 0

I am trying to write a SAS script that will simply read in a SAS .sas7bdat data file and output it in text format. I want dates to be output in YYYYMMDD format. I don’t know what the names of the date columns will be. My script is currently:

libname tmplib '~/testdatadir/';
OPTIONS MISSING='00'x;
data tmpdata;
set tmplib.testdatafile;
array flds{*} _NUMERIC_;
do i=1 to dim(flds);
  if missing(flds(i)) then flds(i)=.;
end;
array charflds{*} _CHARACTER_;
do i=1 to dim(charflds);
  if missing(charflds(i)) then charflds(i)=' ';
end;
drop i;
RUN;

PROC EXPORT
  DATA = tmpdata
  OUTFILE = 'testdataoutfile.txt'
  DBMS = TAB REPLACE;
  PUTNAME = YES;
RUN;

I would either like to iterate through all date fields (as I do with NUMERIC fields and CHARACTER fields), or add a check for each NUMERIC field testing whether it is a date (then I could change the format), or add an option to PROC EXPORT to indicate the output date format. Any other approach to get the output file to have dates formatted as YYYYMMDD would be acceptable as well.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T00:03:45+00:00Added an answer on June 3, 2026 at 12:03 am

    You can use the varfmt function to find the format of a numeric variable, which can help you determine whether it’s a date, i.e. whether its format is a date format. Technically you could have a date that isn’t in a correct date format, so it’s just displayed as 16239 or something, but those are hard to detect because it could also just be the number 16,239. This method will find anything that’s displayed as a date in the data browser.

    Then use some combination of put and input to get it into YYYYMMDD format.

    One issue with just using put is that I think by default it will return a character variable, so you’ll either need to create a new character variable to hold the date, or convert the YYYYMMDD back into an 8-digit number, so the number 20120501 instead of the character string 20120501.

    For example 2, you should note that varfmt returns the format of a variable given the dataset name and a variable number. In the example they set up a separate vars table whose purpose is to loop through all the variables.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to write a couple of functions that will encrypt or decrypt a file
I am trying write a function that generates simulated data but if the simulated
im trying to write an app that will display a list off lines from
I'm trying write a simple perl script that reads some fields from a password
Trying to write a PowerShell cmdlet that will mute the sound at start, unless
I'm trying to write a program that will play MP3's. This program will also
I am trying write a query that will display if the person has anyone
I'm trying write a Ruby script that checks if user credentials are valid using
I need an idea on how to read text file data between quotes. For
Trying to write a simple jQuery function that will multiple the index of an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.